Refactor how blocks drop into the base Block/TE class. Fixes drop issues

This commit is contained in:
tterrag1098 committed 2015-02-02 18:23:09 -05:00
1 parent 3b60517968
commit d9863b7a2e
20 files changed
+168 -301

No files matched your search

@@ -1,14 +1,23 @@
package crazypants.enderio;
import java.util.ArrayList;
import javax.annotation.Nullable;
import com.google.common.collect.Lists;
import net.minecraft.block.Block;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.machine.AbstractMachineEntity;
public abstract class BlockEio extends Block {
@@ -60,4 +69,45 @@ public abstract class BlockEio extends Block {
blockIcon = iIconRegister.registerIcon("enderio:" + name);
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return doNormalDrops(world, x, y, z) ? super.getDrops(world, x, y, z, metadata, fortune) : new ArrayList<ItemStack>();
}
/* Subclass Helpers */
protected boolean doNormalDrops(World world, int x, int y, int z) {
return true;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean doHarvest) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityEio && ((TileEntityEio) te).shouldDrop()) {
if(!world.isRemote && (!player.capabilities.isCreativeMode) && !doNormalDrops(world, x, y, z)) {
dropAsItem(world, x, y, z, (AbstractMachineEntity) te);
}
((TileEntityEio) te).preventDrops();
}
return super.removedByPlayer(world, player, x, y, z, false);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityEio && ((TileEntityEio) te).shouldDrop()) {
dropAsItem(world, x, y, z, (TileEntityEio) te);
}
super.breakBlock(world, x, y, z, block, meta);
}
protected void dropAsItem(World world, int x, int y, int z, TileEntityEio te) {
int meta = damageDropped(world.getBlockMetadata(x, y, z));
ItemStack itemStack = new ItemStack(this, 1, meta);
processDrop(world, x, y, z, te, itemStack);
dropBlockAsItem(world, x, y, z, itemStack);
}
protected void processDrop(World world, int x, int y, int z, @Nullable TileEntityEio te, ItemStack drop) {
}
}
@@ -11,6 +11,8 @@ import net.minecraft.tileentity.TileEntity;
*/
public abstract class TileEntityEio extends TileEntity {
private boolean shouldDrop = true;
@Override
public final void readFromNBT(NBTTagCompound root) {
super.readFromNBT(root);
@@ -48,4 +50,12 @@ public abstract class TileEntityEio extends TileEntity {
protected boolean isPoweredRedstone() {
return worldObj.getStrongestIndirectPower(xCoord, yCoord, zCoord) > 0;
}
public void preventDrops() {
shouldDrop = false;
}
public boolean shouldDrop() {
return shouldDrop;
}
}
@@ -8,14 +8,14 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.BlockEio;
import crazypants.enderio.ModObject;
import crazypants.enderio.conduit.IConduitBundle;
import crazypants.enderio.machine.painter.IPaintedBlock;
public class BlockConduitFacade extends Block implements IPaintedBlock{
public class BlockConduitFacade extends BlockEio implements IPaintedBlock {
public static BlockConduitFacade create() {
BlockConduitFacade result = new BlockConduitFacade();
@@ -26,18 +26,11 @@ public class BlockConduitFacade extends Block implements IPaintedBlock{
private Block blockOverride;
private BlockConduitFacade() {
super(new Material(MapColor.stoneColor));
setHardness(0.5F);
super(ModObject.blockConduitFacade.unlocalisedName, null, new Material(MapColor.stoneColor));
setStepSound(Block.soundTypeStone);
setHarvestLevel("pickaxe", 0);
setBlockName(ModObject.blockConduitFacade.unlocalisedName);
setCreativeTab(null);
}
private void init() {
GameRegistry.registerBlock(this, ModObject.blockConduitFacade.unlocalisedName);
}
@Override
public void registerBlockIcons(IIconRegister IIconRegister) {
blockIcon = IIconRegister.registerIcon("enderio:conduitFacade");
@@ -146,11 +146,4 @@ public class BlockEnderIO extends BlockEio implements IResourceTooltipProvider {
public String getUnlocalizedNameForTooltip(ItemStack stack) {
return getUnlocalizedName();
}
public void breakBlock(World world, int x, int y, int z, Block block, int p_149749_6_) {
super.breakBlock(world, x, y, z, block, p_149749_6_);
world.removeTileEntity(x, y, z);
}
}
@@ -4,7 +4,6 @@ import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
@@ -17,22 +16,23 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.BlockEio;
import crazypants.enderio.ClientProxy;
import crazypants.enderio.EnderIO;
import crazypants.enderio.EnderIOTab;
import crazypants.enderio.ModObject;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.api.tool.ITool;
import crazypants.enderio.gui.IResourceTooltipProvider;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.tool.ToolUtil;
import crazypants.enderio.waila.IWailaInfoProvider;
public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> extends BlockContainer implements IGuiHandler, IResourceTooltipProvider,
public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> extends BlockEio implements IGuiHandler, IResourceTooltipProvider,
IWailaInfoProvider {
public static int renderId;
@@ -52,8 +52,6 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
protected final ModObject modObject;
protected final Class<T> teClass;
static {
PacketHandler.INSTANCE.registerMessage(PacketIoMode.class, PacketIoMode.class, PacketHandler.nextID(), Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketItemBuffer.class, PacketItemBuffer.class, PacketHandler.nextID(), Side.SERVER);
@@ -62,12 +60,10 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
}
protected AbstractMachineBlock(ModObject mo, Class<T> teClass, Material mat) {
super(mat);
super(mo.unlocalisedName, teClass, mat);
modObject = mo;
this.teClass = teClass;
setHardness(2.0F);
setStepSound(soundTypeMetal);
setBlockName(mo.unlocalisedName);
setCreativeTab(EnderIOTab.tabEnderIO);
setHarvestLevel("pickaxe", 0);
random = new Random();
@@ -83,16 +79,6 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
EnderIO.guiHandler.registerGuiHandler(getGuiId(), this);
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
try {
return teClass.newInstance();
} catch (Exception e) {
FMLCommonHandler.instance().raiseException(e, "Could not create tile entity from class " + teClass, true);
return null;
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
@@ -210,41 +196,13 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
}
@Override
public int quantityDropped(Random r) {
return 0;
}
protected boolean shouldDropDefaultItem(World world, EntityPlayer player, int x, int y, int z) {
return true;
protected boolean doNormalDrops(World world, int x, int y, int z) {
return false;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean doHarvest) {
if(!world.isRemote && (!player.capabilities.isCreativeMode)) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof AbstractMachineEntity && shouldDropDefaultItem(world, player, x, y, z)) {
dropAsItem(world, x, y, z, (AbstractMachineEntity) te);
}
}
world.removeTileEntity(x, y, z);
return super.removedByPlayer(world, player, x, y, z, doHarvest);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof AbstractMachineEntity) {
dropAsItem(world, x, y, z, (AbstractMachineEntity) te);
}
super.breakBlock(world, x, y, z, block, meta);
}
private void dropAsItem(World world, int x, int y, int z, AbstractMachineEntity te) {
AbstractMachineEntity machineEntity = (AbstractMachineEntity) te;
int meta = damageDropped(world.getBlockMetadata(x, y, z));
ItemStack itemStack = new ItemStack(this, 1, meta);
machineEntity.writeToItemStack(itemStack);
dropBlockAsItem(world, x, y, z, itemStack);
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack stack) {
((AbstractMachineEntity) te).writeToItemStack(stack);
}
@Override
@@ -38,11 +38,11 @@ public class BlockBuffer extends AbstractMachineBlock<TileBuffer> implements IFa
res.init();
return res;
}
private static final String[] textureNames = new String[] { "blockBufferItem", "blockBufferPower", "blockBufferOmni", "blockBufferCreative" };
@SideOnly(Side.CLIENT)
private IIcon[] textures;
private BlockBuffer() {
super(ModObject.blockBuffer, TileBuffer.class);
}
@@ -77,7 +77,7 @@ public class BlockBuffer extends AbstractMachineBlock<TileBuffer> implements IFa
protected int getGuiId() {
return GuiHandler.GUI_ID_BUFFER;
}
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iIconRegister) {
@@ -87,7 +87,7 @@ public class BlockBuffer extends AbstractMachineBlock<TileBuffer> implements IFa
textures[i] = iIconRegister.registerIcon("enderio:" + textureNames[i]);
}
}
@Override
protected String getMachineFrontIconKey(boolean active) {
return getSideIconKey(active);
@@ -97,7 +97,7 @@ public class BlockBuffer extends AbstractMachineBlock<TileBuffer> implements IFa
public IIcon getIcon(int blockSide, int blockMeta) {
return blockSide > 1 ? textures[blockMeta] : super.getIcon(blockSide, blockMeta);
}
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int blockSide) {
TileEntity te = world.getTileEntity(x, y, z);
@@ -105,7 +105,7 @@ public class BlockBuffer extends AbstractMachineBlock<TileBuffer> implements IFa
TileBuffer tef = (TileBuffer) te;
if(tef.getSourceBlock() != null) {
return tef.getSourceBlock().getIcon(blockSide, tef.getSourceBlockMetadata());
} else if (blockSide > 1){
} else if(blockSide > 1) {
return textures[world.getBlockMetadata(x, y, z)];
}
}
@@ -126,30 +126,6 @@ public class BlockBuffer extends AbstractMachineBlock<TileBuffer> implements IFa
}
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return Lists.newArrayList();
}
@Override
protected boolean shouldDropDefaultItem(World world, EntityPlayer player, int x, int y, int z) {
return false;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
if(!world.isRemote) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileBuffer) {
TileBuffer cb = (TileBuffer) te;
if(!player.capabilities.isCreativeMode) {
dropBlockAsItem(world, x, y, z, createDrop(cb));
}
}
}
return super.removedByPlayer(world, player, x, y, z, willHarvest);
}
// TODO refactor machines so all have this functionality
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
@@ -482,7 +482,6 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
Util.dropItems(world, cb.getInventory(), x, y, z, true);
}
}
world.removeTileEntity(x, y, z);
}
@Override
@@ -90,32 +90,20 @@ public class BlockEnchanter extends BlockEio implements IGuiHandler, IResourceTo
return true;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean harvested) {
if(!world.isRemote) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEnchanter && !player.capabilities.isCreativeMode) {
dropAsItem(world, x, y, z, (TileEnchanter) te);
world.removeTileEntity(x, y, z);
}
}
return super.removedByPlayer(world, player, x, y, z, harvested);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEnchanter) {
dropAsItem(world, x, y, z, (TileEnchanter) te);
dropItems(world, x, y, z, (TileEnchanter) te);
}
super.breakBlock(world, x, y, z, block, meta);
world.removeTileEntity(x, y, z);
}
private void dropAsItem(World world, int x, int y, int z, TileEnchanter te) {
ItemStack itemStack = new ItemStack(this);
dropBlockAsItem(world, x, y, z, itemStack);
protected boolean doNormalDrops(World world, int x, int y, int z) {
return false;
}
private void dropItems(World world, int x, int y, int z, TileEnchanter te) {
if(te.getStackInSlot(0) != null) {
Util.dropItems(world, te.getStackInSlot(0), x, y, z, true);
}
@@ -272,8 +272,6 @@ public class BlockHyperCube extends BlockEio implements IGuiHandler, IResourceTo
return true;
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new ContainerHyperCube();
@@ -293,11 +291,4 @@ public class BlockHyperCube extends BlockEio implements IGuiHandler, IResourceTo
public String getUnlocalizedNameForTooltip(ItemStack stack) {
return getUnlocalizedName();
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int p_149749_6_) {
super.breakBlock(world, x, y, z, block, p_149749_6_);
world.removeTileEntity(x, y, z);
}
}
@@ -20,6 +20,7 @@ import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.BlockEio;
import crazypants.enderio.ModObject;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.api.redstone.IRedstoneConnectable;
import crazypants.enderio.api.tool.ITool;
import crazypants.enderio.tool.ToolUtil;
@@ -178,17 +179,19 @@ public class BlockElectricLight extends BlockEio implements IRedstoneConnectable
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
ItemStack stack = player.getCurrentEquippedItem();
if (stack == null) {
if(stack == null) {
return false;
}
ITool tool = ToolUtil.getEquippedTool(player);
if(tool != null && tool.canUse(stack, player, x, y, z) && player.isSneaking() && !world.isRemote) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileElectricLight) {
if(te instanceof TileElectricLight) {
((TileElectricLight) te).onBlockRemoved();
world.setBlockToAir(x, y, z);
if(!player.capabilities.isCreativeMode) {
dropBlockAsItem(world, x, y, z, createDrop((TileElectricLight) te));
ItemStack drop = new ItemStack(this);
processDrop(world, x, y, z, (TileEntityEio) te, drop);
dropBlockAsItem(world, x, y, z, drop);
}
tool.used(stack, player, x, y, z);
}
@@ -199,55 +202,32 @@ public class BlockElectricLight extends BlockEio implements IRedstoneConnectable
@Override
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
TileEntity t = world.getTileEntity(x, y, z);
TileElectricLight te = null;
if(t instanceof TileElectricLight) {
te = (TileElectricLight) t;
}
if(t != null) {
te.onBlockRemoved();
world.removeTileEntity(x, y, z);
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileElectricLight) {
((TileElectricLight) te).onBlockRemoved();
}
}
@Override
public int quantityDropped(Random r) {
return 0;
}
private ItemStack createDrop(TileElectricLight te) {
int meta = te.isInvereted() ? 1 : 0;
if(!te.isRequiresPower()) {
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack drop) {
TileElectricLight light = (TileElectricLight) te;
int meta = light.isInvereted() ? 1 : 0;
if(!light.isRequiresPower()) {
meta += 2;
} else if (te.isWireless()) {
} else if(light.isWireless()) {
meta += 4;
}
ItemStack st = new ItemStack(this, 1, meta);
return st;
drop.setItemDamage(meta);
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
if(!world.isRemote) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileElectricLight) {
TileElectricLight cb = (TileElectricLight) te;
if(!player.capabilities.isCreativeMode) {
dropBlockAsItem(world, x, y, z, createDrop(cb));
}
}
}
return super.removedByPlayer(world, player, x, y, z, willHarvest);
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
if (te != null && te instanceof TileElectricLight) {
return createDrop((TileElectricLight) te);
ItemStack stack = new ItemStack(this);
if(te instanceof TileElectricLight) {
processDrop(world, x, y, z, (TileEntityEio) te, stack);
}
return new ItemStack(this);
return stack;
}
/* IRedstoneConnectable */
@@ -62,7 +62,6 @@ public class BlockLightNode extends BlockEio {
if(te != null) {
te.onBlockRemoved();
}
world.removeTileEntity(x, y, z);
}
@Override
@@ -1,8 +1,6 @@
package crazypants.enderio.machine.monitor;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
@@ -14,7 +12,7 @@ import crazypants.enderio.machine.AbstractMachineBlock;
import crazypants.enderio.network.PacketHandler;
import crazypants.util.DyeColor;
public class BlockPowerMonitor extends AbstractMachineBlock<TilePowerMonitor> implements ITileEntityProvider {
public class BlockPowerMonitor extends AbstractMachineBlock<TilePowerMonitor> {
public static BlockPowerMonitor create() {
@@ -28,14 +28,16 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.BlockEio;
import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.MachineRecipeRegistry;
import crazypants.util.IFacade;
import crazypants.util.Lang;
public class BlockPaintedGlowstone extends Block implements ITileEntityProvider, IPaintedBlock, IFacade {
public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvider, IPaintedBlock, IFacade {
public static int renderId = -1;
@@ -50,15 +52,15 @@ public class BlockPaintedGlowstone extends Block implements ITileEntityProvider,
private Random rand = new Random();
protected BlockPaintedGlowstone() {
super(Material.glass);
super(ModObject.blockPaintedGlowstone.unlocalisedName, TileEntityPaintedBlock.class, Material.glass);
setCreativeTab(null);
setBlockName(ModObject.blockPaintedGlowstone.unlocalisedName);
setStepSound(soundTypeGlass);
setHardness(0.7F);
setLightLevel(1.0f);
}
private void init() {
@Override
protected void init() {
GameRegistry.registerBlock(this, BlockItemPaintedGlowstone.class, ModObject.blockPaintedGlowstone.unlocalisedName);
GameRegistry.registerTileEntity(TileEntityPaintedBlock.class, ModObject.blockPaintedGlowstone.unlocalisedName + "TileEntity");
MachineRecipeRegistry.instance.registerRecipe(ModObject.blockPainter.unlocalisedName, new PainterTemplate());
@@ -207,29 +209,11 @@ public class BlockPaintedGlowstone extends Block implements ITileEntityProvider,
super.onBlockPlacedBy(world, x, y, z, player, stack);
}
/**
* Remove the tile entity too.
*/
@Override
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
if(!world.isRemote && world.getGameRules().getGameRuleBooleanValue("doTileDrops")) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntityPaintedBlock) {
TileEntityPaintedBlock tef = (TileEntityPaintedBlock) te;
ItemStack itemStack = createItemStackForSourceBlock(tef.getSourceBlock(), tef.getSourceBlockMetadata());
float f = 0.7F;
double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, itemStack);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
}
}
world.removeTileEntity(x, y, z);
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack drop) {
TileEntityPaintedBlock tef = (TileEntityPaintedBlock) te;
ItemStack itemStack = createItemStackForSourceBlock(tef.getSourceBlock(), tef.getSourceBlockMetadata());
drop.stackTagCompound = (NBTTagCompound) itemStack.stackTagCompound.copy();
}
@Override
@@ -219,7 +219,7 @@ public class BlockPaintedSlab extends BlockSlab implements ITileEntityProvider,
}
}
}
return super.removedByPlayer(world, player, x, y, z, doHarvest);
return super.removedByPlayer(world, player, x, y, z, false);
}
@Override
@@ -346,7 +346,6 @@ public class BlockCapacitorBank extends BlockEio implements IGuiHandler, IAdvanc
TileCapacitorBank cb = (TileCapacitorBank) te;
Util.dropItems(world, cb, x, y, z, true);
}
world.removeTileEntity(x, y, z);
}
@Override
@@ -42,7 +42,7 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
IIcon sideIcon;
IIcon advancedSideIcon;
IIcon advancedIcon;
IIcon borderIcon;
IIcon advancedBorderIcon;
@@ -104,7 +104,7 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
public IIcon getBorderIcon(int i, int meta) {
return meta == 0 ? borderIcon : advancedBorderIcon;
}
@Override
public int getRenderType() {
return renderId;
@@ -145,12 +145,6 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int p_149749_6_) {
super.breakBlock(world, x, y, z, block, p_149749_6_);
world.removeTileEntity(x, y, z);
}
@Override
public String getUnlocalizedNameForTooltip(ItemStack itemStack) {
return getUnlocalizedName();
@@ -158,7 +152,7 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
@Override
public void getWailaInfo(List<String> tooltip, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileEntitySolarPanel) {
TileEntitySolarPanel solar = (TileEntitySolarPanel) te;
float efficiency = solar.calculateLightRatio();
@@ -134,11 +134,6 @@ public class BlockTank extends AbstractMachineBlock<TileTank> implements IAdvanc
return super.onBlockActivated(world, x, y, z, entityPlayer, par6, par7, par8, par9);
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileTank(var2);
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
TileEntity te = world.getTileEntity(x, y, z);
@@ -1,10 +1,6 @@
package crazypants.enderio.machine.vacuum;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -15,6 +11,7 @@ import crazypants.enderio.BlockEio;
import crazypants.enderio.EnderIO;
import crazypants.enderio.GuiHandler;
import crazypants.enderio.ModObject;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.gui.IResourceTooltipProvider;
import crazypants.enderio.tool.ToolUtil;
@@ -32,9 +29,9 @@ public class BlockVacuumChest extends BlockEio implements IGuiHandler, IResource
super(ModObject.blockVacuumChest.unlocalisedName, TileVacuumChest.class);
setBlockTextureName("enderio:blockVacuumChest");
}
@Override
protected void init() {
protected void init() {
super.init();
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_VACUUM_CHEST, this);
}
@@ -53,53 +50,31 @@ public class BlockVacuumChest extends BlockEio implements IGuiHandler, IResource
}
return true;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean harvested) {
if(!world.isRemote) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileVacuumChest) {
TileVacuumChest cb = (TileVacuumChest) te;
if(!player.capabilities.isCreativeMode || "true".equalsIgnoreCase(System.getProperty("blockCapBankAllwaysDrop"))) {
ItemStack itemStack = createItemStackWithInventory(cb);
float f = 0.7F;
double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
EntityItem entityitem = new EntityItem(world, x + d0, y + d1, z + d2, itemStack);
entityitem.delayBeforeCanPickup = 10;
world.spawnEntityInWorld(entityitem);
}
}
}
return super.removedByPlayer(world, player, x, y, z, harvested);
protected boolean doNormalDrops(World world, int x, int y, int z) {
return false;
}
@Override
public int quantityDropped(Random p_149745_1_) {
return 0;
}
private ItemStack createItemStackWithInventory(TileVacuumChest cb) {
ItemStack stack = new ItemStack(this);
stack.stackTagCompound = new NBTTagCompound();
cb.writeContentsToNBT(stack.stackTagCompound);
return stack;
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack drop) {
drop.stackTagCompound = new NBTTagCompound();
((TileVacuumChest) te).writeContentsToNBT(drop.stackTagCompound);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase placedBy, ItemStack stack) {
if(!world.isRemote) {
TileEntity te = world.getTileEntity(x, y, z);
if(stack != null && stack.stackTagCompound != null && te instanceof TileVacuumChest) {
((TileVacuumChest)te).readContentsFromNBT(stack.stackTagCompound);
if(stack != null && stack.stackTagCompound != null && te instanceof TileVacuumChest) {
((TileVacuumChest) te).readContentsFromNBT(stack.stackTagCompound);
world.markBlockForUpdate(x, y, z);
}
}
}
@Override
public int getRenderType() {
public int getRenderType() {
return renderId;
}
@@ -126,12 +101,6 @@ public class BlockVacuumChest extends BlockEio implements IGuiHandler, IResource
return null;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int p_149749_6_) {
super.breakBlock(world, x, y, z, block, p_149749_6_);
world.removeTileEntity(x, y, z);
}
@Override
public String getUnlocalizedNameForTooltip(ItemStack itemStack) {
return getUnlocalizedName();
@@ -11,17 +11,16 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import crazypants.enderio.ModObject;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.config.Config;
import crazypants.render.BoundingBox;
import crazypants.util.BlockCoord;
import crazypants.util.ItemUtil;
public class TileVacuumChest extends TileEntity implements IEntitySelector, IInventory {
public class TileVacuumChest extends TileEntityEio implements IEntitySelector, IInventory {
private static final double RANGE = Config.vacuumChestRange;
private ItemStack[] inv = new ItemStack[27];
@@ -31,7 +30,7 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
doHoover();
}
}
@Override
public boolean isEntityApplicable(Entity entity) {
if(entity.isDead) {
@@ -46,7 +45,6 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
}
return false;
}
private void doHoover() {
@@ -65,9 +63,9 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
hooverEntity(entity);
} else {
double speed = 0.06;
double distScale = 1.0 - Math.min(0.9, distance / (RANGE*RANGE));
double distScale = 1.0 - Math.min(0.9, distance / (RANGE * RANGE));
distScale *= distScale;
entity.motionX += x / distance * distScale * speed;
entity.motionY += y / distance * distScale * 0.2;
entity.motionZ += z / distance * distScale * speed;
@@ -75,7 +73,7 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
}
}
private void hooverEntity(Entity entity) {
if(!worldObj.isRemote) {
if(entity instanceof EntityItem && !entity.isDead) {
@@ -91,9 +89,9 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
}
}
}
private boolean isFull() {
for(ItemStack stack : inv) {
for (ItemStack stack : inv) {
if(stack == null || stack.stackSize < stack.getMaxStackSize()) {
return false;
}
@@ -143,12 +141,12 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
@Override
public void setInventorySlotContents(int slot, ItemStack contents) {
if(slot < 0 || slot >= inv.length) {
System.out.println("TileVacumChest.setInventorySlotContents: " + slot);
return;
}
if(contents == null) {
inv[slot] = contents;
} else {
@@ -164,9 +162,9 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
public ItemStack getStackInSlotOnClosing(int var1) {
return null;
}
@Override
public String getInventoryName() {
public String getInventoryName() {
return ModObject.blockVacuumChest.unlocalisedName;
}
@@ -176,16 +174,16 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
}
@Override
public boolean isUseableByPlayer(EntityPlayer var1) {
public boolean isUseableByPlayer(EntityPlayer var1) {
return true;
}
@Override
public void openInventory() {
public void openInventory() {
}
@Override
public void closeInventory() {
public void closeInventory() {
}
@Override
@@ -194,11 +192,11 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
}
@Override
public void readFromNBT(NBTTagCompound nbtRoot) {
super.readFromNBT(nbtRoot);
public void readCustomNBT(NBTTagCompound nbtRoot) {
super.readFromNBT(nbtRoot);
readContentsFromNBT(nbtRoot);
}
public void readContentsFromNBT(NBTTagCompound nbtRoot) {
NBTTagList itemList = (NBTTagList) nbtRoot.getTag("Items");
if(itemList != null) {
@@ -213,11 +211,11 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
}
@Override
public void writeToNBT(NBTTagCompound nbtRoot) {
public void writeCustomNBT(NBTTagCompound nbtRoot) {
super.writeToNBT(nbtRoot);
writeContentsToNBT(nbtRoot);
}
}
public void writeContentsToNBT(NBTTagCompound nbtRoot) {
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++) {
@@ -230,5 +228,5 @@ public class TileVacuumChest extends TileEntity implements IEntitySelector, IIn
}
nbtRoot.setTag("Items", itemList);
}
}
@@ -8,6 +8,7 @@ import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
@@ -21,6 +22,7 @@ import crazypants.enderio.BlockEio;
import crazypants.enderio.EnderIO;
import crazypants.enderio.GuiHandler;
import crazypants.enderio.ModObject;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.config.Config;
import crazypants.enderio.gui.IResourceTooltipProvider;
import crazypants.enderio.machine.MachineRecipeInput;
@@ -44,7 +46,7 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
public static BlockTravelAnchor create() {
PacketHandler.INSTANCE.registerMessage(PacketAccessMode.class, PacketAccessMode.class, PacketHandler.nextID(), Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketLabel.class, PacketLabel.class, PacketHandler.nextID(), Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketLabel.class, PacketLabel.class, PacketHandler.nextID(), Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketTravelEvent.class, PacketTravelEvent.class, PacketHandler.nextID(), Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketDrainStaff.class, PacketDrainStaff.class, PacketHandler.nextID(), Side.SERVER);
PacketHandler.INSTANCE.registerMessage(PacketOpenAuthGui.class, PacketOpenAuthGui.class, PacketHandler.nextID(), Side.SERVER);
@@ -163,31 +165,22 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
}
return null;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean doHarvest) {
if(!world.isRemote && (!player.capabilities.isCreativeMode)) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof TileTravelAnchor) {
TileTravelAnchor anchor = (TileTravelAnchor) te;
ItemStack itemStack;
Block srcBlk = anchor.getSourceBlock();
if(srcBlk != null) {
itemStack = createItemStackForSourceBlock(anchor.getSourceBlock(), anchor.getSourceBlockMetadata());
} else {
itemStack = new ItemStack(this);
}
dropBlockAsItem(world, x, y, z, itemStack);
}
@Override
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack drop) {
TileTravelAnchor anchor = (TileTravelAnchor) te;
ItemStack itemStack = new ItemStack(this);
Block srcBlk = anchor.getSourceBlock();
if(srcBlk != null) {
itemStack = createItemStackForSourceBlock(anchor.getSourceBlock(), anchor.getSourceBlockMetadata());
drop.stackTagCompound = (NBTTagCompound) itemStack.stackTagCompound.copy();
}
return super.removedByPlayer(world, player, x, y, z, doHarvest);
}
@Override
public int quantityDropped(Random par1Random) {
return 0; // need to do custom dropping to maintain source metadata
protected boolean doNormalDrops(World world, int x, int y, int z) {
return false;
}
@Override
@@ -246,8 +239,8 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
@Override
public int getFacadeMetadata(IBlockAccess world, int x, int y, int z, int side) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileTravelAnchor) {
return ((TileTravelAnchor)te).getSourceBlockMetadata();
if(te instanceof TileTravelAnchor) {
return ((TileTravelAnchor) te).getSourceBlockMetadata();
}
return 0;
}
@@ -255,8 +248,8 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
@Override
public Block getFacade(IBlockAccess world, int x, int y, int z, int side) {
TileEntity te = world.getTileEntity(x, y, z);
if (te instanceof TileTravelAnchor) {
return ((TileTravelAnchor)te).getSourceBlock();
if(te instanceof TileTravelAnchor) {
return ((TileTravelAnchor) te).getSourceBlock();
}
return this;
}