Finish refactoring wrenching/itemdrops into base classes.

Also fix conduits not rendering break texture
This commit is contained in:
tterrag1098 committed 2015-02-03 19:22:24 -05:00
1 parent 01194de240
commit d3417225d1
23 files changed
+218 -313

No files matched your search

+44 -8
View File
@@ -4,8 +4,6 @@ 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;
@@ -14,10 +12,13 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.api.tool.ITool;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.tool.ToolUtil;
public abstract class BlockEio extends Block {
@@ -75,8 +76,40 @@ public abstract class BlockEio extends Block {
}
/* Subclass Helpers */
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
protected boolean doNormalDrops(World world, int x, int y, int z) {
if(shouldWrench(world, x, y, z, entityPlayer, side) && ToolUtil.breakBlockWithTool(this, world, x, y, z, entityPlayer)) {
return true;
}
ITool tool = ToolUtil.getEquippedTool(entityPlayer);
if(tool != null && !entityPlayer.isSneaking()) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof AbstractMachineEntity) {
((AbstractMachineEntity) te).toggleIoModeForFace(ForgeDirection.getOrientation(side));
world.markBlockForUpdate(x, y, z);
return true;
}
}
if(entityPlayer.isSneaking()) {
return false;
}
return openGui(world, x, y, z, entityPlayer, side);
}
protected boolean shouldWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
return true;
}
protected boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
return false;
}
public boolean doNormalDrops(World world, int x, int y, int z) {
return true;
}
@@ -84,10 +117,12 @@ public abstract class BlockEio extends Block {
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);
if(!world.isRemote && !player.capabilities.isCreativeMode && !doNormalDrops(world, x, y, z)) {
dropAsItem(world, x, y, z, (TileEntityEio) te);
((TileEntityEio) te).preventDrops();
} else if(player.capabilities.isCreativeMode) {
((TileEntityEio) te).preventDrops();
}
((TileEntityEio) te).preventDrops();
}
return super.removedByPlayer(world, player, x, y, z, false);
}
@@ -95,13 +130,14 @@ public abstract class BlockEio extends Block {
@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()) {
if(te instanceof TileEntityEio && ((TileEntityEio) te).shouldDrop() && !doNormalDrops(world, x, y, z)) {
dropAsItem(world, x, y, z, (TileEntityEio) te);
((TileEntityEio)te).preventDrops();
}
super.breakBlock(world, x, y, z, block, meta);
}
protected void dropAsItem(World world, int x, int y, int z, TileEntityEio te) {
public 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);
@@ -57,6 +57,11 @@ public class BlockReinforcedObsidian extends BlockEio implements IResourceToolti
public String getUnlocalizedNameForTooltip(ItemStack itemStack) {
return getUnlocalizedName();
}
@Override
protected boolean shouldWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
return false;
}
@Override
public void getWailaInfo(List<String> tooltip, EntityPlayer player, World world, int x, int y, int z) {}
@@ -157,7 +157,7 @@ public class ConduitBundleRenderer extends TileEntitySpecialRenderer implements
}
facb.setBlockOverride(null);
bundle.setFacadeId(facadeId, false);
bundle.setFacadeId(facadeId, false);
} else if(facadeId != null) {
bundle.setFacadeRenderAs(FacadeRenderState.FULL);
boolean isFacadeOpaque = facadeId.isOpaqueCube();
@@ -198,73 +198,67 @@ public class ConduitBundleRenderer extends TileEntitySpecialRenderer implements
List<BoundingBox> wireBounds = new ArrayList<BoundingBox>();
if(BlockConduitBundle.theRenderPass == 0) {
for (IConduit con : bundle.getConduits()) {
for (IConduit con : bundle.getConduits()) {
if(ConduitUtil.renderConduit(player, con)) {
ConduitRenderer renderer = EnderIO.proxy.getRendererForConduit(con);
renderer.renderEntity(this, bundle, con, x, y, z, partialTick, brightness, rb);
Set<ForgeDirection> extCons = con.getExternalConnections();
for (ForgeDirection dir : extCons) {
if(con.getConnectionMode(dir) != ConnectionMode.DISABLED && con.getConnectionMode(dir) != ConnectionMode.NOT_SET) {
externals.add(dir);
}
if(ConduitUtil.renderConduit(player, con)) {
ConduitRenderer renderer = EnderIO.proxy.getRendererForConduit(con);
renderer.renderEntity(this, bundle, con, x, y, z, partialTick, brightness, rb);
Set<ForgeDirection> extCons = con.getExternalConnections();
for (ForgeDirection dir : extCons) {
if(con.getConnectionMode(dir) != ConnectionMode.DISABLED && con.getConnectionMode(dir) != ConnectionMode.NOT_SET) {
externals.add(dir);
}
} else if(con != null) {
Collection<CollidableComponent> components = con.getCollidableComponents();
for (CollidableComponent component : components) {
}
} else if(con != null) {
Collection<CollidableComponent> components = con.getCollidableComponents();
for (CollidableComponent component : components) {
wireBounds.add(component.bound);
}
}
}
// Internal conectors between conduits
List<CollidableComponent> connectors = bundle.getConnectors();
List<CollidableComponent> rendered = Lists.newArrayList();
for (CollidableComponent component : connectors) {
if(component.conduitType != null) {
IConduit conduit = bundle.getConduit(component.conduitType);
if(conduit != null) {
if(ConduitUtil.renderConduit(player, component.conduitType)) {
if(rb.hasOverrideBlockTexture()) {
List<RaytraceResult> results = EnderIO.blockConduitBundle.doRayTraceAll(bundle.getWorld(), MathHelper.floor_double(x),
MathHelper.floor_double(y), MathHelper.floor_double(z), EnderIO.proxy.getClientPlayer());
for (RaytraceResult r : results) {
// the connectors can be rendered multiple times and this makes the break texture look funky
if(r.component.conduitType == component.conduitType && !rendered.contains(r.component)) {
rendered.add(r.component);
CubeRenderer.render(component.bound, rb.overrideBlockTexture, true);
}
}
} else {
tessellator.setBrightness((int) (brightness));
CubeRenderer.render(component.bound, conduit.getTextureForState(component), true);
}
} else {
wireBounds.add(component.bound);
}
}
} else if(ConduitUtil.getDisplayMode(player) == ConduitDisplayMode.ALL && !rb.hasOverrideBlockTexture()) {
IIcon tex = EnderIO.blockConduitBundle.getConnectorIcon(component.data);
CubeRenderer.render(component.bound, tex);
}
}
//render these after the 'normal' conduits so help with proper blending
for (BoundingBox wireBound : wireBounds) {
Tessellator.instance.setColorRGBA_F(1, 1, 1, 0.25f);
CubeRenderer.render(wireBound, EnderIO.blockConduitFacade.getIcon(0, 0));
}
// Internal conectors between conduits
List<CollidableComponent> connectors = bundle.getConnectors();
List<CollidableComponent> rendered = Lists.newArrayList();
for (CollidableComponent component : connectors) {
if(component.conduitType != null) {
IConduit conduit = bundle.getConduit(component.conduitType);
if(conduit != null) {
if(ConduitUtil.renderConduit(player, component.conduitType)) {
if(rb.hasOverrideBlockTexture()) {
List<RaytraceResult> results = EnderIO.blockConduitBundle.doRayTraceAll(bundle.getWorld(), MathHelper.floor_double(x),
MathHelper.floor_double(y), MathHelper.floor_double(z), EnderIO.proxy.getClientPlayer());
for (RaytraceResult r : results) {
// the connectors can be rendered multiple times and this makes the break texture look funky
if(r.component.conduitType == component.conduitType && !rendered.contains(r.component)) {
rendered.add(r.component);
CubeRenderer.render(component.bound, rb.overrideBlockTexture, true);
}
}
} else {
tessellator.setBrightness((int) (brightness));
CubeRenderer.render(component.bound, conduit.getTextureForState(component), true);
}
} else {
wireBounds.add(component.bound);
}
}
} else if(ConduitUtil.getDisplayMode(player) == ConduitDisplayMode.ALL && !rb.hasOverrideBlockTexture()) {
IIcon tex = EnderIO.blockConduitBundle.getConnectorIcon(component.data);
CubeRenderer.render(component.bound, tex);
}
}
} else {
if(!rb.hasOverrideBlockTexture()) {
//render these after the 'normal' conduits so help with proper blending
for (BoundingBox wireBound : wireBounds) {
Tessellator.instance.setColorRGBA_F(1, 1, 1, 0.25f);
CubeRenderer.render(wireBound, EnderIO.blockConduitFacade.getIcon(0, 0));
}
Tessellator.instance.setColorRGBA_F(1, 1, 1, 1f);
// External connection terminations
for (ForgeDirection dir : externals) {
renderExternalConnection(dir);
}
}
Tessellator.instance.setColorRGBA_F(1, 1, 1, 1f);
// External connection terminations
for (ForgeDirection dir : externals) {
renderExternalConnection(dir);
}
tessellator.addTranslation(-(float) x, -(float) y, -(float) z);
@@ -87,19 +87,14 @@ public class BlockEnderIO extends BlockEio implements IResourceTooltipProvider {
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
if(entityPlayer.isSneaking()) {
return false;
}
public boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof ITravelAccessable) {
ITravelAccessable ta = (ITravelAccessable) te;
if(ta.canUiBeAccessed(entityPlayer)) {
if(!world.isRemote) {
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_TRAVEL_ACCESSABLE, world, x, y, z);
}
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_TRAVEL_ACCESSABLE, world, x, y, z);
} else {
if(world.isRemote) {
if(world.isRemote && !entityPlayer.isSneaking()) {
entityPlayer.addChatComponentMessage(new ChatComponentText(Lang.localize("gui.travelAccessable.privateBlock1") + " " + ta.getPlacedBy() + " "
+ Lang.localize("gui.travelAccessable.privateBlock2")));
}
@@ -80,36 +80,17 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
public int getRenderType() {
return renderId;
}
if(ToolUtil.breakBlockWithTool(this, world, x, y, z, entityPlayer)) {
return true;
}
ITool tool = ToolUtil.getEquippedTool(entityPlayer);
if(tool != null && !entityPlayer.isSneaking()) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof AbstractMachineEntity) {
((AbstractMachineEntity) te).toggleIoModeForFace(ForgeDirection.getOrientation(side));
world.markBlockForUpdate(x, y, z);
return true;
}
}
if(entityPlayer.isSneaking()) {
return false;
}
public boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
if(!world.isRemote) {
entityPlayer.openGui(EnderIO.instance, getGuiId(), world, x, y, z);
}
return true;
}
@Override
public int getRenderType() {
return renderId;
}
@Override
public boolean canSilkHarvest(World world, EntityPlayer player, int x, int y, int z, int metadata) {
return false;
@@ -196,13 +177,15 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
}
@Override
protected boolean doNormalDrops(World world, int x, int y, int z) {
public boolean doNormalDrops(World world, int x, int y, int z) {
return false;
}
@Override
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack stack) {
((AbstractMachineEntity) te).writeToItemStack(stack);
if(te != null) {
((AbstractMachineEntity) te).writeToItemStack(stack);
}
}
@Override
@@ -126,6 +126,11 @@ public class BlockBuffer extends AbstractMachineBlock<TileBuffer> implements IFa
}
}
@Override
public int damageDropped(int meta) {
return meta;
}
// TODO refactor machines so all have this functionality
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
@@ -151,11 +151,7 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
if(!(te instanceof TileCapBank)) {
return false;
}
if(ToolUtil.breakBlockWithTool(this, world, x, y, z, entityPlayer)) {
return true;
}
TileCapBank tcb = (TileCapBank) te;
ForgeDirection faceHit = ForgeDirection.getOrientation(side);
@@ -170,11 +166,7 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
return true;
}
if(entityPlayer.isSneaking()) {
return false;
}
if(ToolUtil.isToolEquipped(entityPlayer)) {
if(!entityPlayer.isSneaking() && ToolUtil.isToolEquipped(entityPlayer)) {
IoMode ioMode = tcb.getIoMode(faceHit);
if(faceHit.offsetY == 0) {
@@ -201,6 +193,16 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
return true;
}
return super.onBlockActivated(world, x, y, z, entityPlayer, side, par7, par8, par9);
}
@Override
public boolean doNormalDrops(World world, int x, int y, int z) {
return false;
}
@Override
protected boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
if(!world.isRemote) {
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_CAP_BANK, world, x, y, z);
}
@@ -433,31 +435,15 @@ public class BlockCapBank extends BlockEio implements IGuiHandler, IAdvancedTool
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) {
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 TileCapBank) {
TileCapBank cb = (TileCapBank) te;
cb.moveInventoryToNetwork();
ItemStack itemStack = createItemStack(world, x, y, z, cb);
//Clear in the inventory as its now in the item stack
for (int i = 0; i < cb.getInventory().length; i++) {
cb.getInventory()[i] = null;
}
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);
return super.removedByPlayer(world, player, x, y, z, doHarvest);
}
protected ItemStack createItemStack(World world, int x, int y, int z, TileCapBank cb) {
@@ -69,21 +69,9 @@ public class BlockEnchanter extends BlockEio implements IGuiHandler, IResourceTo
}
world.markBlockForUpdate(x, y, z);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
ITool tool = ToolUtil.getEquippedTool(entityPlayer);
if(tool != null) {
if(entityPlayer.isSneaking() && tool.canUse(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z)) {
removedByPlayer(world, entityPlayer, x, y, z, false);
tool.used(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z);
return true;
}
}
if(entityPlayer.isSneaking()) {
return false;
}
protected boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
if(!world.isRemote) {
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_ENCHANTER, world, x, y, z);
}
@@ -99,7 +87,7 @@ public class BlockEnchanter extends BlockEio implements IGuiHandler, IResourceTo
super.breakBlock(world, x, y, z, block, meta);
}
protected boolean doNormalDrops(World world, int x, int y, int z) {
public boolean doNormalDrops(World world, int x, int y, int z) {
return false;
}
@@ -63,8 +63,6 @@ public abstract class AbstractMachineContainer extends Container {
addSlotToContainer(slot);
playerSlotLocations.put(slot, loc);
}
}
@Override
@@ -255,17 +255,7 @@ public class BlockHyperCube extends BlockEio implements IGuiHandler, IResourceTo
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
if(ToolUtil.breakBlockWithTool(this, world, x, y, z, entityPlayer)) {
return true;
}
if(entityPlayer.isSneaking()) {
return false;
}
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof TileHyperCube)) {
return false;
}
protected boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
if(!world.isRemote) {
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_HYPER_CUBE, world, x, y, z);
}
@@ -175,30 +175,6 @@ public class BlockElectricLight extends BlockEio implements IRedstoneConnectable
((TileElectricLight) te).onNeighborBlockChange(blockID);
}
}
@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) {
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) {
((TileElectricLight) te).onBlockRemoved();
world.setBlockToAir(x, y, z);
if(!player.capabilities.isCreativeMode) {
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);
}
return true;
}
return false;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
@@ -211,6 +187,9 @@ public class BlockElectricLight extends BlockEio implements IRedstoneConnectable
@Override
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack drop) {
TileElectricLight light = (TileElectricLight) te;
if(light == null) {
return;
}
int meta = light.isInvereted() ? 1 : 0;
if(!light.isRequiresPower()) {
meta += 2;
@@ -212,8 +212,10 @@ public class BlockPaintedGlowstone extends BlockEio implements ITileEntityProvid
@Override
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();
if(tef != null) {
ItemStack itemStack = createItemStackForSourceBlock(tef.getSourceBlock(), tef.getSourceBlockMetadata());
drop.stackTagCompound = (NBTTagCompound) itemStack.stackTagCompound.copy();
}
}
@Override
@@ -119,13 +119,6 @@ public class BlockCapacitorBank extends BlockEio implements IGuiHandler, IAdvanc
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
if(ToolUtil.breakBlockWithTool(this, world, x, y, z, entityPlayer)) {
return true;
}
if(entityPlayer.isSneaking()) {
return false;
}
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof TileCapacitorBank)) {
return false;
@@ -145,7 +138,12 @@ public class BlockCapacitorBank extends BlockEio implements IGuiHandler, IAdvanc
return true;
}
return super.onBlockActivated(world, x, y, z, entityPlayer, side, par7, par8, par9);
}
@Override
protected boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
if(!world.isRemote) {
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_CAPACITOR_BANK, world, x, y, z);
}
@@ -1,7 +1,6 @@
package crazypants.enderio.machine.reservoir;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
@@ -16,10 +15,9 @@ import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import crazypants.enderio.EnderIOTab;
import crazypants.enderio.BlockEio;
import crazypants.enderio.ModObject;
import crazypants.enderio.gui.IResourceTooltipProvider;
import crazypants.enderio.machine.reservoir.TileReservoir.Pos;
@@ -29,7 +27,7 @@ import crazypants.util.FluidUtil;
import crazypants.util.Util;
import crazypants.vecmath.Vector3d;
public class BlockReservoir extends BlockContainer implements IResourceTooltipProvider {
public class BlockReservoir extends BlockEio implements IResourceTooltipProvider {
public static BlockReservoir create() {
BlockReservoir result = new BlockReservoir();
@@ -59,21 +57,8 @@ public class BlockReservoir extends BlockContainer implements IResourceTooltipPr
IIcon switchIcon;
private BlockReservoir() {
super(Material.rock);
setHardness(0.5F);
super(ModObject.blockReservoir.unlocalisedName, TileReservoir.class, Material.rock);
setStepSound(Block.soundTypeStone);
setBlockName(ModObject.blockReservoir.unlocalisedName);
setCreativeTab(EnderIOTab.tabEnderIO);
}
@Override
public TileEntity createNewTileEntity(World var1, int var2) {
return new TileReservoir();
}
private void init() {
GameRegistry.registerBlock(this, ModObject.blockReservoir.unlocalisedName);
GameRegistry.registerTileEntity(TileReservoir.class, ModObject.blockReservoir.unlocalisedName + "TileEntity");
}
@Override
@@ -136,8 +121,7 @@ public class BlockReservoir extends BlockContainer implements IResourceTooltipPr
}
}
return false;
return super.onBlockActivated(world, x, y, z, entityPlayer, par6, par7, par8, par9);
}
@Override
@@ -77,22 +77,6 @@ public class BlockSolarPanel extends BlockEio implements IResourceTooltipProvide
return false;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
ITool tool = ToolUtil.getEquippedTool(entityPlayer);
if(tool != null && entityPlayer.isSneaking() && tool.canUse(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z)) {
if(!world.isRemote && !entityPlayer.capabilities.isCreativeMode) {
int meta = world.getBlockMetadata(x, y, z);
ItemStack is = new ItemStack(this, 1, meta);
Util.dropItems(world, is, x, y, z, true);
}
removedByPlayer(world, entityPlayer, x, y, z, true);
tool.used(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z);
return true;
}
return false;
}
@Override
public IIcon getIcon(int side, int meta) {
if(side == ForgeDirection.UP.ordinal()) {
@@ -3,8 +3,10 @@ package crazypants.enderio.machine.tank;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@@ -13,7 +15,6 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.fluids.FluidStack;
@@ -46,16 +47,14 @@ public class BlockTank extends AbstractMachineBlock<TileTank> implements IAdvanc
protected BlockTank() {
super(ModObject.blockTank, TileTank.class);
setStepSound(Block.soundTypeGlass);
setLightOpacity(0);
}
@Override
protected void init() {
GameRegistry.registerBlock(this, BlockItemTank.class, ModObject.blockTank.unlocalisedName);
if(teClass != null) {
GameRegistry.registerTileEntity(teClass, ModObject.blockTank.unlocalisedName + "TileEntity");
}
EnderIO.guiHandler.registerGuiHandler(GuiHandler.GUI_ID_TANK, this);
setLightOpacity(0);
GameRegistry.registerBlock(this, BlockItemTank.class, modObject.unlocalisedName);
GameRegistry.registerTileEntity(teClass, modObject.unlocalisedName + "TileEntity");
EnderIO.guiHandler.registerGuiHandler(getGuiId(), this);
}
@Override
@@ -63,6 +62,18 @@ public class BlockTank extends AbstractMachineBlock<TileTank> implements IAdvanc
return par1;
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void getSubBlocks(Item item, CreativeTabs p_149666_2_, List list) {
list.add(new ItemStack(this, 1, 0));
list.add(new ItemStack(this, 1, 1));
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
return new TileTank(metadata);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
@@ -37,7 +37,7 @@ public class TileTank extends AbstractMachineEntity implements IFluidHandler {
}
public TileTank() {
super(new SlotDefinition(0, 1, 2, 3, -1, -1));
this(0);
}
@Override
@@ -37,29 +37,23 @@ public class BlockVacuumChest extends BlockEio implements IGuiHandler, IResource
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
if(ToolUtil.breakBlockWithTool(this, world, x, y, z, entityPlayer)) {
return true;
}
if(entityPlayer.isSneaking()) {
return false;
}
protected boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
if(!world.isRemote) {
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_VACUUM_CHEST, world, x, y, z);
}
return true;
} return super.openGui(world, x, y, z, entityPlayer, side);
}
@Override
protected boolean doNormalDrops(World world, int x, int y, int z) {
public boolean doNormalDrops(World world, int x, int y, int z) {
return false;
}
@Override
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack drop) {
drop.stackTagCompound = new NBTTagCompound();
((TileVacuumChest) te).writeContentsToNBT(drop.stackTagCompound);
if(te != null) {
((TileVacuumChest) te).writeContentsToNBT(drop.stackTagCompound);
}
}
@Override
@@ -38,21 +38,6 @@ public class BlockWirelessCharger extends BlockEio implements IResourceTooltipPr
setLightOpacity(1);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float par7, float par8, float par9) {
ITool tool = ToolUtil.getEquippedTool(entityPlayer);
if(tool != null && entityPlayer.isSneaking() && tool.canUse(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z)) {
if(!world.isRemote) {
Util.dropItems(world, new ItemStack(this), x, y, z, true);
}
breakBlock(world, x, y, z, this, 0);
world.setBlockToAir(x, y, z);
tool.used(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z);
return true;
}
return false;
}
@Override
public void registerBlockIcons(IIconRegister iIconRegister) {
centerOn = iIconRegister.registerIcon("enderio:blockWirelessChargerOn");
@@ -8,6 +8,7 @@ import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
@@ -36,7 +37,8 @@ public class BlockFusedQuartz extends BlockEio {
FUSED_QUARTZ("fusedQuartz", "enderio:fusedQuartz", "enderio:fusedQuartzFrame", "enderio:fusedQuartzItem"),
GLASS("fusedGlass", "enderio:fusedGlass", Config.clearGlassSameTexture ? "enderio:fusedQuartzFrame" : "enderio:fusedGlassFrame", "enderio:fusedGlassItem"),
ENLIGHTENED_FUSED_QUARTZ("enlightenedFusedQuartz", "enderio:fusedQuartz", "enderio:fusedQuartzFrame", "enderio:fusedQuartzItem"),
ENLIGHTENED_GLASS("enlightenedFusedGlass", "enderio:fusedGlass", Config.clearGlassSameTexture ? "enderio:fusedQuartzFrame" : "enderio:fusedGlassFrame", "enderio:fusedGlassItem");
ENLIGHTENED_GLASS("enlightenedFusedGlass", "enderio:fusedGlass", Config.clearGlassSameTexture ? "enderio:fusedQuartzFrame" : "enderio:fusedGlassFrame",
"enderio:fusedGlassItem");
final String unlocalisedName;
final String blockIcon;
@@ -49,13 +51,13 @@ public class BlockFusedQuartz extends BlockEio {
this.blockIcon = blockIcon;
this.itemIcon = itemIcon;
}
public boolean connectTo(int otherMeta) {
if (otherMeta == ordinal() || Config.clearGlassConnectToFusedQuartz) {
if(otherMeta == ordinal() || Config.clearGlassConnectToFusedQuartz) {
return true;
}
switch(this) {
switch (this) {
case FUSED_QUARTZ:
return otherMeta == ENLIGHTENED_FUSED_QUARTZ.ordinal();
case ENLIGHTENED_FUSED_QUARTZ:
@@ -65,7 +67,7 @@ public class BlockFusedQuartz extends BlockEio {
case ENLIGHTENED_GLASS:
return otherMeta == GLASS.ordinal();
}
return false;
}
}
@@ -180,13 +182,13 @@ public class BlockFusedQuartz extends BlockEio {
}
@Override
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
if(side == ForgeDirection.UP) { //stop drips
return false;
return false;
}
return true;
return true;
}
@Override
public boolean canPlaceTorchOnTop(World arg0, int arg1, int arg2, int arg3) {
return true;
@@ -225,33 +227,9 @@ public class BlockFusedQuartz extends BlockEio {
return frameIcons[meta];
}
/**
* 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(world.getBlockMetadata(x, y, z), tef.getSourceBlock(), tef.getSourceBlockMetadata());
if(itemStack != null) {
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);
}
}
}
super.breakBlock(world, x, y, z, par5, par6);
protected boolean shouldWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
return false;
}
private ItemStack createItemStackForSourceBlock(int quartzBlockMeta, Block sourceBlock, int sourceBlockMetadata) {
@@ -80,6 +80,11 @@ public class BlockIngotStorage extends BlockEio implements IAdvancedTooltipProvi
public boolean isBeaconBase(IBlockAccess worldObj, int x, int y, int z, int beaconX, int beaconY, int beaconZ) {
return true;
}
@Override
protected boolean shouldWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
return false;
}
@Override
public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
@@ -116,28 +116,22 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
}
}
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
if(entityPlayer.isSneaking()) {
return false;
}
public boolean openGui(World world, int x, int y, int z, EntityPlayer entityPlayer, int side) {
TileEntity te = world.getTileEntity(x, y, z);
if(te instanceof ITravelAccessable) {
ITravelAccessable ta = (ITravelAccessable) te;
if(ta.canUiBeAccessed(entityPlayer)) {
if(!world.isRemote) {
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_TRAVEL_ACCESSABLE, world, x, y, z);
}
entityPlayer.openGui(EnderIO.instance, GuiHandler.GUI_ID_TRAVEL_ACCESSABLE, world, x, y, z);
} else {
if(world.isRemote) {
if(world.isRemote && !entityPlayer.isSneaking()) {
entityPlayer.addChatComponentMessage(new ChatComponentText(Lang.localize("gui.travelAccessable.privateBlock1") + " " + ta.getPlacedBy() + " "
+ Lang.localize("gui.travelAccessable.privateBlock2")));
}
}
return true;
}
return false;
return true;
}
@Override
@@ -170,6 +164,10 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
protected void processDrop(World world, int x, int y, int z, TileEntityEio te, ItemStack drop) {
TileTravelAnchor anchor = (TileTravelAnchor) te;
if(anchor == null) {
return;
}
ItemStack itemStack = new ItemStack(this);
Block srcBlk = anchor.getSourceBlock();
if(srcBlk != null) {
@@ -179,7 +177,7 @@ public class BlockTravelAnchor extends BlockEio implements IGuiHandler, ITileEnt
}
@Override
protected boolean doNormalDrops(World world, int x, int y, int z) {
public boolean doNormalDrops(World world, int x, int y, int z) {
return false;
}
@@ -13,8 +13,10 @@ import net.minecraft.world.World;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import crazypants.enderio.BlockEio;
import crazypants.enderio.EnderIO;
import crazypants.enderio.Log;
import crazypants.enderio.TileEntityEio;
import crazypants.enderio.api.tool.ITool;
import crazypants.enderio.item.ItemYetaWrench;
@@ -35,6 +37,11 @@ public class ToolUtil {
public static boolean breakBlockWithTool(Block block, World world, int x, int y, int z, EntityPlayer entityPlayer) {
ITool tool = ToolUtil.getEquippedTool(entityPlayer);
if(tool != null && entityPlayer.isSneaking() && tool.canUse(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z)) {
if(entityPlayer.capabilities.isCreativeMode && block instanceof BlockEio) {
((BlockEio) block).dropAsItem(world, x, y, z, (TileEntityEio) world.getTileEntity(x, y, z));
} else if(!(block instanceof BlockEio) || ((BlockEio) block).doNormalDrops(world, x, y, z)) {
block.dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
}
block.removedByPlayer(world, entityPlayer, x, y, z, true);
tool.used(entityPlayer.getCurrentEquippedItem(), entityPlayer, x, y, z);
return true;