quantumTank now holds fluid when broken with a wrench

This commit is contained in:
modmuss50 2015-04-11 19:13:31 +01:00
parent 28abe89511
commit 66c1e7ec34
3 changed files with 55 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import techreborn.blocks.BlockThermalGenerator;
import techreborn.client.TechRebornCreativeTab; import techreborn.client.TechRebornCreativeTab;
import techreborn.itemblocks.ItemBlockOre; import techreborn.itemblocks.ItemBlockOre;
import techreborn.itemblocks.ItemBlockQuantumChest; import techreborn.itemblocks.ItemBlockQuantumChest;
import techreborn.itemblocks.ItemBlockQuantumTank;
import techreborn.tiles.TileQuantumChest; import techreborn.tiles.TileQuantumChest;
import techreborn.tiles.TileQuantumTank; import techreborn.tiles.TileQuantumTank;
import techreborn.tiles.TileThermalGenerator; import techreborn.tiles.TileThermalGenerator;
@ -28,7 +29,7 @@ public class ModBlocks {
GameRegistry.registerTileEntity(TileThermalGenerator.class, "TileThermalGenerator"); GameRegistry.registerTileEntity(TileThermalGenerator.class, "TileThermalGenerator");
quantumTank = new BlockQuantumTank().setBlockName("techreborn.quantumTank").setBlockTextureName("techreborn:quantumTank").setCreativeTab(TechRebornCreativeTab.instance); quantumTank = new BlockQuantumTank().setBlockName("techreborn.quantumTank").setBlockTextureName("techreborn:quantumTank").setCreativeTab(TechRebornCreativeTab.instance);
GameRegistry.registerBlock(quantumTank, "techreborn.quantumTank"); GameRegistry.registerBlock(quantumTank, ItemBlockQuantumTank.class, "techreborn.quantumTank");
GameRegistry.registerTileEntity(TileQuantumTank.class, "TileQuantumTank"); GameRegistry.registerTileEntity(TileQuantumTank.class, "TileQuantumTank");
quantumChest = new BlockQuantumChest().setBlockName("techreborn.quantumChest").setBlockTextureName("techreborn:quantumChest").setCreativeTab(TechRebornCreativeTab.instance); quantumChest = new BlockQuantumChest().setBlockName("techreborn.quantumChest").setBlockTextureName("techreborn:quantumChest").setCreativeTab(TechRebornCreativeTab.instance);

View file

@ -0,0 +1,34 @@
package techreborn.itemblocks;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import techreborn.init.ModBlocks;
import techreborn.tiles.TileQuantumTank;
public class ItemBlockQuantumTank extends ItemBlock {
public ItemBlockQuantumTank(Block block) {
super(block);
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata)
{
if (!world.setBlock(x, y, z, ModBlocks.quantumTank, metadata, 3)) {
return false;
}
if (world.getBlock(x, y, z) == ModBlocks.quantumTank) {
world.getBlock(x, y, z).onBlockPlacedBy(world, x, y, z, player, stack);
world.getBlock(x, y, z).onPostBlockPlaced(world, x, y, z, metadata);
}
if (stack != null && stack.hasTagCompound()) {
((TileQuantumTank) world.getTileEntity(x, y, z)).readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
}
return true;
}
}

View file

@ -27,6 +27,10 @@ public class TileQuantumTank extends TileEntity implements IFluidHandler, IInven
@Override @Override
public void readFromNBT(NBTTagCompound tagCompound) { public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound); super.readFromNBT(tagCompound);
readFromNBTWithoutCoords(tagCompound);
}
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {
tank.readFromNBT(tagCompound); tank.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound); inventory.readFromNBT(tagCompound);
} }
@ -34,10 +38,15 @@ public class TileQuantumTank extends TileEntity implements IFluidHandler, IInven
@Override @Override
public void writeToNBT(NBTTagCompound tagCompound) { public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound); super.writeToNBT(tagCompound);
writeToNBTWithoutCoords(tagCompound);
}
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound) {
tank.writeToNBT(tagCompound); tank.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound); inventory.writeToNBT(tagCompound);
} }
public Packet getDescriptionPacket() { public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound(); NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag); writeToNBT(nbtTag);
@ -180,6 +189,15 @@ public class TileQuantumTank extends TileEntity implements IFluidHandler, IInven
@Override @Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) { public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.quantumTank); return getDropWithNBT();
}
public ItemStack getDropWithNBT() {
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.quantumTank, 1);
writeToNBTWithoutCoords(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
} }
} }