Added Universal Cell
This commit is contained in:
parent
9035f2a21c
commit
e38c800f21
13 changed files with 179 additions and 24 deletions
94
src/main/java/techreborn/items/DynamicCell.java
Normal file
94
src/main/java/techreborn/items/DynamicCell.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
package techreborn.items;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.entity.player.FillBucketEvent;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.UniversalBucket;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.init.ModItems;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 17/05/2016.
|
||||
*/
|
||||
public class DynamicCell extends UniversalBucket{
|
||||
|
||||
public DynamicCell() {
|
||||
super(1000, new ItemStack(ModItems.emptyCell), false);
|
||||
setCreativeTab(TechRebornCreativeTab.instance);
|
||||
setUnlocalizedName("techreborn.cellFilled");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> onItemRightClick(ItemStack itemstack, World world, EntityPlayer player, EnumHand hand) {
|
||||
return ActionResult.newResult(EnumActionResult.FAIL, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFillBucket(FillBucketEvent event) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemStackDisplayName(ItemStack stack)
|
||||
{
|
||||
FluidStack fluidStack = getFluid(stack);
|
||||
if (fluidStack == null)
|
||||
{
|
||||
if(getEmpty() != null)
|
||||
{
|
||||
return getEmpty().getDisplayName();
|
||||
}
|
||||
return super.getItemStackDisplayName(stack);
|
||||
}
|
||||
|
||||
return fluidStack.getLocalizedName() + " Cell";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ItemStack container, FluidStack resource, boolean doFill)
|
||||
{
|
||||
// has to be exactly 1, must be handled from the caller
|
||||
if (container.stackSize != 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// can only fill exact capacity
|
||||
if (resource == null || resource.amount != getCapacity())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// fill the container
|
||||
if (doFill)
|
||||
{
|
||||
NBTTagCompound tag = container.getTagCompound();
|
||||
if (tag == null)
|
||||
{
|
||||
tag = new NBTTagCompound();
|
||||
}
|
||||
resource.writeToNBT(tag);
|
||||
container.setTagCompound(tag);
|
||||
}
|
||||
return getCapacity();
|
||||
}
|
||||
|
||||
public static ItemStack getCellWithFluid(Fluid fluid, int stackSize){
|
||||
ItemStack stack = new ItemStack(ModItems.dynamicCell, stackSize);
|
||||
ModItems.dynamicCell.fill(stack, new FluidStack(fluid, ModItems.dynamicCell.getCapacity()), true);
|
||||
return stack;
|
||||
}
|
||||
|
||||
public static ItemStack getCellWithFluid(Fluid fluid){
|
||||
ItemStack stack = new ItemStack(ModItems.dynamicCell);
|
||||
ModItems.dynamicCell.fill(stack, new FluidStack(fluid, ModItems.dynamicCell.getCapacity()), true);
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
25
src/main/java/techreborn/items/EmptyCell.java
Normal file
25
src/main/java/techreborn/items/EmptyCell.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package techreborn.items;
|
||||
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 17/05/2016.
|
||||
*/
|
||||
public class EmptyCell extends ItemTextureBase {
|
||||
|
||||
public EmptyCell()
|
||||
{
|
||||
setUnlocalizedName("techreborn.cell");
|
||||
setCreativeTab(TechRebornCreativeTab.instance);
|
||||
}
|
||||
@Override
|
||||
public String getTextureName(int damage) {
|
||||
return ModInfo.MOD_ID + ":items/cell_base";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMeta() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ import techreborn.client.TechRebornCreativeTab;
|
|||
import techreborn.init.ModItems;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
@Deprecated
|
||||
public class ItemCells extends ItemTextureBase implements IFluidContainerItem
|
||||
{
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue