quantumChest now holds items when broken with a wrench
This commit is contained in:
parent
4cdf4aa7db
commit
28abe89511
6 changed files with 75 additions and 6 deletions
|
@ -33,6 +33,7 @@ public class BlockQuantumChest extends BlockContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||||
|
if(!player.isSneaking())
|
||||||
player.openGui(Core.INSTANCE, GuiHandler.quantumChestID, world, x, y, z);
|
player.openGui(Core.INSTANCE, GuiHandler.quantumChestID, world, x, y, z);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ public class BlockQuantumTank extends BlockContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||||
|
if(!player.isSneaking())
|
||||||
player.openGui(Core.INSTANCE, GuiHandler.quantumTankID, world, x, y, z);
|
player.openGui(Core.INSTANCE, GuiHandler.quantumTankID, world, x, y, z);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ public class BlockThermalGenerator extends BlockContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||||
|
if(!player.isSneaking())
|
||||||
player.openGui(Core.INSTANCE, GuiHandler.thermalGeneratorID, world, x, y, z);
|
player.openGui(Core.INSTANCE, GuiHandler.thermalGeneratorID, world, x, y, z);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import techreborn.blocks.BlockQuantumTank;
|
||||||
import techreborn.blocks.BlockThermalGenerator;
|
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.tiles.TileQuantumChest;
|
import techreborn.tiles.TileQuantumChest;
|
||||||
import techreborn.tiles.TileQuantumTank;
|
import techreborn.tiles.TileQuantumTank;
|
||||||
import techreborn.tiles.TileThermalGenerator;
|
import techreborn.tiles.TileThermalGenerator;
|
||||||
|
@ -31,7 +32,7 @@ public class ModBlocks {
|
||||||
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);
|
||||||
GameRegistry.registerBlock(quantumChest, "techreborn.quantumChest");
|
GameRegistry.registerBlock(quantumChest, ItemBlockQuantumChest.class, "techreborn.quantumChest");
|
||||||
GameRegistry.registerTileEntity(TileQuantumChest.class, "TileQuantumChest");
|
GameRegistry.registerTileEntity(TileQuantumChest.class, "TileQuantumChest");
|
||||||
|
|
||||||
ore = new BlockOre(Material.rock);
|
ore = new BlockOre(Material.rock);
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.network.NetworkManager;
|
import net.minecraft.network.NetworkManager;
|
||||||
import net.minecraft.network.Packet;
|
import net.minecraft.network.Packet;
|
||||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||||
|
@ -78,6 +77,10 @@ public class TileQuantumChest extends TileEntity implements IInventory ,IWrencha
|
||||||
@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) {
|
||||||
inventory.readFromNBT(tagCompound);
|
inventory.readFromNBT(tagCompound);
|
||||||
|
|
||||||
storedItem = null;
|
storedItem = null;
|
||||||
|
@ -96,6 +99,10 @@ public class TileQuantumChest extends TileEntity implements IInventory ,IWrencha
|
||||||
@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) {
|
||||||
inventory.writeToNBT(tagCompound);
|
inventory.writeToNBT(tagCompound);
|
||||||
if (storedItem != null)
|
if (storedItem != null)
|
||||||
{
|
{
|
||||||
|
@ -192,6 +199,16 @@ public class TileQuantumChest extends TileEntity implements IInventory ,IWrencha
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue