mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-26 15:03:07 +00:00
Refactor how blocks drop into the base Block/TE class. Fixes drop issues
This commit is contained in:
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) {
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user