From 3c4c153ad3365b6814e8500605dbd56501a6f725 Mon Sep 17 00:00:00 2001 From: Matthias Mann Date: Wed, 4 Feb 2015 20:08:58 +0100 Subject: [PATCH] let the wireless charger keep it's stored energy when picked up --- .../wireless/BlockWirelessCharger.java | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/main/java/crazypants/enderio/machine/wireless/BlockWirelessCharger.java b/src/main/java/crazypants/enderio/machine/wireless/BlockWirelessCharger.java index 0b2feb8a..b6daa47b 100644 --- a/src/main/java/crazypants/enderio/machine/wireless/BlockWirelessCharger.java +++ b/src/main/java/crazypants/enderio/machine/wireless/BlockWirelessCharger.java @@ -1,8 +1,9 @@ package crazypants.enderio.machine.wireless; import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.IBlockAccess; @@ -11,11 +12,9 @@ import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import crazypants.enderio.BlockEio; import crazypants.enderio.ModObject; -import crazypants.enderio.api.tool.ITool; +import crazypants.enderio.TileEntityEio; import crazypants.enderio.gui.IResourceTooltipProvider; import crazypants.enderio.network.PacketHandler; -import crazypants.enderio.tool.ToolUtil; -import crazypants.util.Util; public class BlockWirelessCharger extends BlockEio implements IResourceTooltipProvider /* IGuiHandler */{ @@ -104,4 +103,29 @@ public class BlockWirelessCharger extends BlockEio implements IResourceTooltipPr return getUnlocalizedName(); } + @Override + public boolean doNormalDrops(World world, int x, int y, int z) { + return false; + } + + @Override + public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { + super.onBlockPlacedBy(world, x, y, z, player, stack); + + if(stack.stackTagCompound != null) { + TileEntity te = world.getTileEntity(x, y, z); + if(te instanceof TileWirelessCharger) { + ((TileWirelessCharger) te).readCustomNBT(stack.stackTagCompound); + } + } + } + + @Override + protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack drop) { + drop.stackTagCompound = new NBTTagCompound(); + if(te instanceof TileWirelessCharger) { + ((TileWirelessCharger) te).writeCustomNBT(drop.stackTagCompound); + } + } + }