mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-24 05:54:27 +00:00
1 parent
1e46da8afa
commit
849d87bb7d
3 files changed
+66
-23
No files matched your search
@@ -2,12 +2,18 @@ package crazypants.enderio.machine.tank;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlockWithMetadata;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
import com.enderio.core.api.client.gui.IAdvancedTooltipProvider;
|
||||
|
||||
@@ -15,8 +21,9 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.tool.SmartTank;
|
||||
|
||||
public class BlockItemTank extends ItemBlockWithMetadata implements IAdvancedTooltipProvider {
|
||||
public class BlockItemTank extends ItemBlockWithMetadata implements IAdvancedTooltipProvider, IFluidContainerItem {
|
||||
|
||||
public BlockItemTank() {
|
||||
super(EnderIO.blockTank,EnderIO.blockTank);
|
||||
@@ -64,7 +71,44 @@ public class BlockItemTank extends ItemBlockWithMetadata implements IAdvancedToo
|
||||
public void addDetailedEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
|
||||
EnderIO.blockTank.addDetailedEntries(itemstack, entityplayer, list, flag);
|
||||
}
|
||||
|
||||
private static final FluidTank dummy = new SmartTank(FluidRegistry.WATER, 16000);
|
||||
|
||||
private FluidTank loadTank(ItemStack stack) {
|
||||
if (stack.hasTagCompound()) {
|
||||
FluidTank tank = TileTank.loadTank(stack.getTagCompound());
|
||||
return tank != null ? tank : dummy;
|
||||
}
|
||||
return dummy;
|
||||
}
|
||||
|
||||
private void saveTank(ItemStack stack, FluidTank tank) {
|
||||
TileTank.saveTank(stack.getTagCompound(), tank);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid(ItemStack container) {
|
||||
return loadTank(container).getFluid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity(ItemStack container) {
|
||||
return loadTank(container).getCapacity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ItemStack container, FluidStack resource, boolean doFill) {
|
||||
FluidTank tank = loadTank(container);
|
||||
int ret = tank.fill(resource, doFill);
|
||||
saveTank(container, tank);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) {
|
||||
FluidTank tank = loadTank(container);
|
||||
FluidStack ret = tank.drain(maxDrain, doDrain);
|
||||
saveTank(container, tank);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,6 @@ package crazypants.enderio.machine.tank;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
@@ -18,8 +17,6 @@ import crazypants.enderio.EnderIO;
|
||||
|
||||
public class TankItemRenderer implements IItemRenderer {
|
||||
|
||||
private RenderItem ri = new RenderItem();
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
@@ -32,33 +29,24 @@ public class TankItemRenderer implements IItemRenderer {
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
|
||||
if(data != null && data.length > 0) {
|
||||
if (data != null && data.length > 0) {
|
||||
renderToInventory(item, (RenderBlocks) data[0]);
|
||||
}
|
||||
}
|
||||
|
||||
public void renderToInventory(ItemStack item, RenderBlocks renderBlocks) {
|
||||
|
||||
boolean hasFluid = false;
|
||||
if(item.stackTagCompound != null) {
|
||||
TileTank tt = new TileTank();
|
||||
tt.readCommon(item.stackTagCompound);
|
||||
|
||||
TankFluidRenderer.renderTankFluid(tt.tank, 0, -0.1f, 0);
|
||||
hasFluid = true;
|
||||
if (item.hasTagCompound()) {
|
||||
TankFluidRenderer.renderTankFluid(TileTank.loadTank(item.stackTagCompound), 0, -0.1f, 0);
|
||||
}
|
||||
|
||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||
Block block = EnderIO.blockTank;
|
||||
int meta = item.getItemDamage();
|
||||
|
||||
|
||||
IIcon[] icons = RenderUtil.getBlockTextures(block, meta);
|
||||
BoundingBox bb = BoundingBox.UNIT_CUBE.translate(0, -0.1f, 0);
|
||||
Tessellator.instance.startDrawingQuads();
|
||||
CubeRenderer.render(bb, icons, null, RenderUtil.getDefaultPerSideBrightness());
|
||||
Tessellator.instance.draw();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -334,31 +334,43 @@ public class TileTank extends AbstractMachineEntity implements IFluidHandler, IT
|
||||
@Override
|
||||
public void writeCommon(NBTTagCompound nbtRoot) {
|
||||
super.writeCommon(nbtRoot);
|
||||
nbtRoot.setInteger("tankType",getBlockMetadata());
|
||||
nbtRoot.setInteger("tankType", getBlockMetadata());
|
||||
saveTank(nbtRoot, tank);
|
||||
}
|
||||
|
||||
public static void saveTank(NBTTagCompound nbtRoot, FluidTank tank) {
|
||||
if(tank.getFluidAmount() > 0) {
|
||||
NBTTagCompound fluidRoot = new NBTTagCompound();
|
||||
tank.getFluid().writeToNBT(fluidRoot);
|
||||
nbtRoot.setTag("tankContents", fluidRoot);
|
||||
} else {
|
||||
nbtRoot.removeTag("tankContents");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readCommon(NBTTagCompound nbtRoot) {
|
||||
super.readCommon(nbtRoot);
|
||||
tank = loadTank(nbtRoot);
|
||||
}
|
||||
|
||||
public static SmartTank loadTank(NBTTagCompound nbtRoot) {
|
||||
int tankType = nbtRoot.getInteger("tankType");
|
||||
tankType = MathHelper.clamp_int(tankType, 0, 1);
|
||||
SmartTank ret;
|
||||
if(tankType == 1) {
|
||||
tank = new SmartTank(32000);
|
||||
ret = new SmartTank(32000);
|
||||
} else {
|
||||
tank = new SmartTank(16000);
|
||||
ret = new SmartTank(16000);
|
||||
}
|
||||
|
||||
if(nbtRoot.hasKey("tankContents")) {
|
||||
FluidStack fl = FluidStack.loadFluidStackFromNBT((NBTTagCompound) nbtRoot.getTag("tankContents"));
|
||||
tank.setFluid(fl);
|
||||
ret.setFluid(fl);
|
||||
} else {
|
||||
tank.setFluid(null);
|
||||
ret.setFluid(null);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -375,5 +387,4 @@ public class TileTank extends AbstractMachineEntity implements IFluidHandler, IT
|
||||
public void setTanksDirty() {
|
||||
tankDirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user