quantumChest now holds items when broken with a wrench

This commit is contained in:
modmuss50 2015-04-11 19:08:22 +01:00
parent 4cdf4aa7db
commit 28abe89511
6 changed files with 75 additions and 6 deletions

View file

@ -33,7 +33,8 @@ public class BlockQuantumChest extends BlockContainer {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
player.openGui(Core.INSTANCE, GuiHandler.quantumChestID, world, x, y, z);
if(!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.quantumChestID, world, x, y, z);
return true;
}

View file

@ -32,7 +32,8 @@ public class BlockQuantumTank extends BlockContainer {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
player.openGui(Core.INSTANCE, GuiHandler.quantumTankID, world, x, y, z);
if(!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.quantumTankID, world, x, y, z);
return true;
}

View file

@ -55,7 +55,8 @@ public class BlockThermalGenerator extends BlockContainer {
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
player.openGui(Core.INSTANCE, GuiHandler.thermalGeneratorID, world, x, y, z);
if(!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.thermalGeneratorID, world, x, y, z);
return true;
}

View file

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

View file

@ -0,0 +1,48 @@
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.TileQuantumChest;
import java.util.List;
public class ItemBlockQuantumChest extends ItemBlock {
public ItemBlockQuantumChest(Block p_i45328_1_) {
super(p_i45328_1_);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
if (stack != null && stack.hasTagCompound()) {
if (stack.getTagCompound().getCompoundTag("tileEntity") != null)
list.add(stack.getTagCompound().getCompoundTag("tileEntity").getInteger("storedQuantity") + " items");
}
}
@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.quantumChest, metadata, 3)) {
return false;
}
if (world.getBlock(x, y, z) == ModBlocks.quantumChest) {
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()) {
((TileQuantumChest) world.getTileEntity(x, y, z)).readFromNBTWithoutCoords(stack.getTagCompound().getCompoundTag("tileEntity"));
}
return true;
}
}

View file

@ -5,7 +5,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
@ -78,6 +77,10 @@ public class TileQuantumChest extends TileEntity implements IInventory ,IWrencha
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
readFromNBTWithoutCoords(tagCompound);
}
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {
inventory.readFromNBT(tagCompound);
storedItem = null;
@ -96,6 +99,10 @@ public class TileQuantumChest extends TileEntity implements IInventory ,IWrencha
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
writeToNBTWithoutCoords(tagCompound);
}
public void writeToNBTWithoutCoords(NBTTagCompound tagCompound) {
inventory.writeToNBT(tagCompound);
if (storedItem != null)
{
@ -192,6 +199,16 @@ public class TileQuantumChest extends TileEntity implements IInventory ,IWrencha
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.quantumChest);
return getDropWithNBT();
}
public ItemStack getDropWithNBT() {
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.quantumChest, 1);
writeToNBTWithoutCoords(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.stackTagCompound.setTag("tileEntity", tileEntity);
return dropStack;
}
}