diff --git a/src/main/java/gregtech/api/GregTech_API.java b/src/main/java/gregtech/api/GregTech_API.java index 97692443..f00570e2 100644 --- a/src/main/java/gregtech/api/GregTech_API.java +++ b/src/main/java/gregtech/api/GregTech_API.java @@ -23,6 +23,8 @@ import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.SoundEvent; import net.minecraft.world.World; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fml.relauncher.Side; @@ -219,8 +221,11 @@ public class GregTech_API { /** * Adds Biomes to the Biome Lists for World Generation */ + + private static int size = 0; /* Used to assign Minecraft IDs to our SoundEvents. We don't use them. */ static { sItemStackMappings.add(sCoverItems); + size = SoundEvent.REGISTRY.getKeys().size(); sDimensionalList.add(-1); sDimensionalList.add(0); @@ -230,33 +235,42 @@ public class GregTech_API { sSoundList.put(1, "block.anvil.use");//SoundEvents.BLOCK_ANVIL_USE.getSoundName().toString()); sSoundList.put(2, "block.anvil.break");//SoundEvents.BLOCK_ANVIL_BREAK.getSoundName().toString()); sSoundList.put(3, "block.stone_button.click_on");//SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON.getSoundName().toString()); - sSoundList.put(4, "entity.item.break");//SoundEvents.ENTITY_ITEM_BREAK.getSoundName().toString()); + sSoundList.put(4, "block.fire.extinguish");//SoundEvents.ENTITY_ITEM_BREAK.getSoundName().toString()); sSoundList.put(5, "entity.generic.explode");//SoundEvents.ENTITY_GENERIC_EXPLODE.getSoundName().toString()); sSoundList.put(6, "item.firecharge.use");//SoundEvents.ITEM_FIRECHARGE_USE.getSoundName().toString()); - sSoundList.put(100, aTextIC2Lower + ":" + "tools.Wrench"); - sSoundList.put(101, aTextIC2Lower + ":" + "tools.RubberTrampoline"); - sSoundList.put(102, aTextIC2Lower + ":" + "tools.Painter"); - sSoundList.put(103, aTextIC2Lower + ":" + "tools.BatteryUse"); - sSoundList.put(104, aTextIC2Lower + ":" + "tools.chainsaw.ChainsawUseOne"); - sSoundList.put(105, aTextIC2Lower + ":" + "tools.chainsaw.ChainsawUseTwo"); - sSoundList.put(106, aTextIC2Lower + ":" + "tools.drill.DrillSoft"); - sSoundList.put(107, aTextIC2Lower + ":" + "tools.drill.DrillHard"); - sSoundList.put(108, aTextIC2Lower + ":" + "tools.ODScanner"); + registerSound(100, aTextIC2Lower + ":" + "tools.Wrench"); + registerSound(101, aTextIC2Lower + ":" + "tools.RubberTrampoline"); + registerSound(102, aTextIC2Lower + ":" + "tools.Painter"); + registerSound(103, aTextIC2Lower + ":" + "tools.BatteryUse"); + registerSound(104, aTextIC2Lower + ":" + "tools.chainsaw.ChainsawUseOne"); + registerSound(105, aTextIC2Lower + ":" + "tools.chainsaw.ChainsawUseTwo"); + registerSound(106, aTextIC2Lower + ":" + "tools.drill.DrillSoft"); + registerSound(107, aTextIC2Lower + ":" + "tools.drill.DrillHard"); + registerSound(108, aTextIC2Lower + ":" + "tools.ODScanner"); - sSoundList.put(200, aTextIC2Lower + ":" + "machines.ExtractorOp"); - sSoundList.put(201, aTextIC2Lower + ":" + "machines.MaceratorOp"); - sSoundList.put(202, aTextIC2Lower + ":" + "machines.InductionLoop"); - sSoundList.put(203, aTextIC2Lower + ":" + "machines.CompressorOp"); - sSoundList.put(204, aTextIC2Lower + ":" + "machines.RecyclerOp"); - sSoundList.put(205, aTextIC2Lower + ":" + "machines.MinerOp"); - sSoundList.put(206, aTextIC2Lower + ":" + "machines.PumpOp"); - sSoundList.put(207, aTextIC2Lower + ":" + "machines.ElectroFurnaceLoop"); - sSoundList.put(208, aTextIC2Lower + ":" + "machines.InductionLoop"); - sSoundList.put(209, aTextIC2Lower + ":" + "machines.MachineOverload"); - sSoundList.put(210, aTextIC2Lower + ":" + "machines.InterruptOne"); - sSoundList.put(211, aTextIC2Lower + ":" + "machines.KaChing"); - sSoundList.put(212, aTextIC2Lower + ":" + "machines.MagnetizerLoop"); + registerSound(200, aTextIC2Lower + ":" + "machines.ExtractorOp"); + registerSound(201, aTextIC2Lower + ":" + "machines.MaceratorOp"); + registerSound(202, aTextIC2Lower + ":" + "machines.InductionLoop"); + registerSound(203, aTextIC2Lower + ":" + "machines.CompressorOp"); + registerSound(204, aTextIC2Lower + ":" + "machines.RecyclerOp"); + registerSound(205, aTextIC2Lower + ":" + "machines.MinerOp"); + registerSound(206, aTextIC2Lower + ":" + "machines.PumpOp"); + registerSound(207, aTextIC2Lower + ":" + "machines.ElectroFurnaceLoop"); + registerSound(208, aTextIC2Lower + ":" + "machines.InductionLoop"); + registerSound(209, aTextIC2Lower + ":" + "machines.MachineOverload"); + registerSound(210, aTextIC2Lower + ":" + "machines.InterruptOne"); + registerSound(211, aTextIC2Lower + ":" + "machines.KaChing"); + registerSound(212, aTextIC2Lower + ":" + "machines.MagnetizerLoop"); + } + + public static void registerSound(int id, String name) { + ResourceLocation loc = new ResourceLocation(name); + SoundEvent e = new SoundEvent(loc); + if(!SoundEvent.REGISTRY.containsKey(loc)) { + SoundEvent.REGISTRY.register(size++, loc, e); + } + sSoundList.put(id, name); } /** @@ -373,7 +387,6 @@ public class GregTech_API { GT_ItemStack stack = new GT_ItemStack(aStack); int coverId = stack.hashCode(); sCoverItems.put(stack, coverId); - System.out.println(); sCovers.put(coverId, aCover == null || !aCover.isValidTexture() ? Textures.BlockIcons.ERROR_RENDERING[0] : aCover); if (aBehavior != null) sCoverBehaviors.put(coverId, aBehavior); } diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java b/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java index 5be185b4..97a2a12b 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IRedstoneEmitter.java @@ -34,4 +34,10 @@ public interface IRedstoneEmitter extends IHasWorldObjectAndCoords { * Gets the Output for the comparator on the given Side */ byte getComparatorValue(byte aSide); + + /** + * Return whether the TileEntity can output redstone to the given side. Used to visually connect + * vanilla redstone wires. + */ + boolean canOutputRedstone(byte aSide); } \ No newline at end of file diff --git a/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java b/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java index c7d2925d..84944153 100644 --- a/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java +++ b/src/main/java/gregtech/api/items/GT_MetaGenerated_Tool.java @@ -511,10 +511,8 @@ public abstract class GT_MetaGenerated_Tool extends GT_MetaBase_Item implements } public IToolStats getToolStats(ItemStack aStack) { - if(isItemStackUsable(aStack)) { - return getToolStatsInternal(aStack); - } - return null; + // if(isItemStackUsable(aStack)) { // why? + return getToolStatsInternal(aStack); } private IToolStats getToolStatsInternal(ItemStack aStack) { @@ -712,7 +710,7 @@ public abstract class GT_MetaGenerated_Tool extends GT_MetaBase_Item implements @SideOnly(Side.CLIENT) public int getColorFromItemStack(ItemStack stack, int tintIndex) { IToolStats toolStats = getToolStats(stack); - if(tintIndex == 1) { + if(tintIndex > 1) { short[] colorsHead = toolStats.getRGBa(true, stack); if(colorsHead != null) return ITexture.color(colorsHead, true); diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index e12826e2..f43bd60f 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -293,7 +293,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE } if (mNeedsBlockUpdate) { - worldObj.notifyBlockOfStateChange(getPos(), getBlockType()); + worldObj.notifyNeighborsOfStateChange(getPos(), getBlockType()); mNeedsBlockUpdate = false; } } @@ -494,6 +494,12 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE return getInternalInputRedstoneSignal(aSide) > 0; } + @Override + public boolean canOutputRedstone(byte aSide) { + return (getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) + || getCoverBehaviorAtSide(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)); + } + public ITexture getCoverTexture(byte aSide) { return GregTech_API.sCovers.get(getCoverIDAtSide(aSide)); } @@ -1017,7 +1023,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getInputRedstoneSignal(byte aSide) { - return (byte) (worldObj.getRedstonePower(getPos(), EnumFacing.VALUES[aSide]) & 15); + return (byte) (worldObj.getRedstonePower(getPos().offset(EnumFacing.VALUES[aSide]), EnumFacing.VALUES[aSide]) & 15); } @Override diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index ba85b835..87eb8191 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -557,7 +557,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE } if (mNeedsBlockUpdate) { - worldObj.notifyBlockOfStateChange(getPos(), getBlockOffset(0, 0, 0)); + worldObj.notifyNeighborsOfStateChange(getPos(), getBlockOffset(0, 0, 0)); mNeedsBlockUpdate = false; } } @@ -734,6 +734,12 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE return getInternalInputRedstoneSignal(aSide) > 0; } + @Override + public boolean canOutputRedstone(byte aSide) { + return (getCoverBehaviorAtSide(aSide).manipulatesSidedRedstoneOutput(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this) + || getCoverBehaviorAtSide(aSide).letsRedstoneGoOut(aSide, getCoverIDAtSide(aSide), getCoverDataAtSide(aSide), this)); + } + public ITexture getCoverTexture(byte aSide) { return GregTech_API.sCovers.get(getCoverIDAtSide(aSide)); } @@ -1437,7 +1443,7 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE @Override public byte getInputRedstoneSignal(byte aSide) { - return (byte) (worldObj.getRedstonePower(getPos(), EnumFacing.VALUES[aSide]) & 15); + return (byte) (worldObj.getRedstonePower(getPos().offset(EnumFacing.VALUES[aSide]), EnumFacing.VALUES[aSide]) & 15); } @Override diff --git a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java index e31d96cc..503cc4cf 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java @@ -2,6 +2,7 @@ package gregtech.api.metatileentity; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords; +import gregtech.api.net.GT_Packet_Block_Event; import gregtech.api.util.GT_Utility; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -472,7 +473,14 @@ public abstract class BaseTileEntity extends TileEntity implements IHasWorldObje @Override public final void sendBlockEvent(byte aID, byte aValue) { - //NW.sendPacketToAllPlayersInRange(worldObj, new GT_Packet_Block_Event(getXCoord(), (short) getYCoord(), getZCoord(), aID, aValue), getXCoord(), getZCoord()); + NW.sendToAllAround(worldObj, new GT_Packet_Block_Event(getXCoord(), + (short) getYCoord(), + getZCoord(), + aID, + aValue), + getXCoord(), + getYCoord(), + getZCoord()); } private boolean crossedChunkBorder(int aX, int aZ) { diff --git a/src/main/java/gregtech/api/net/GT_PacketHandler.java b/src/main/java/gregtech/api/net/GT_PacketHandler.java index c68fa97f..c17a1127 100644 --- a/src/main/java/gregtech/api/net/GT_PacketHandler.java +++ b/src/main/java/gregtech/api/net/GT_PacketHandler.java @@ -1,6 +1,8 @@ package gregtech.api.net; import gregtech.GT_Mod; +import net.minecraft.client.Minecraft; +import net.minecraft.util.IThreadListener; import net.minecraft.world.World; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; @@ -14,6 +16,7 @@ public class GT_PacketHandler extends SimpleNetworkWrapper { super("gregtech_network"); registerMessage(0, GT_Packet_TileEntity.class, Side.CLIENT); registerMessage(2, GT_Packet_Sound.class, Side.CLIENT); + registerMessage(3, GT_Packet_Block_Event.class, Side.CLIENT); } public void registerMessage(int discriminator, Class packet, Side handleSide) { @@ -32,11 +35,19 @@ public class GT_PacketHandler extends SimpleNetworkWrapper { @Override public GT_Packet onMessage(GT_Packet message, MessageContext ctx) { + IThreadListener listener; + World world; if(ctx.side == Side.SERVER) { - message.process(ctx.getServerHandler().playerEntity.worldObj); + world = ctx.getServerHandler().playerEntity.worldObj; + listener = world.getMinecraftServer(); } else { - message.process(GT_Mod.gregtechproxy.getThePlayer().worldObj); + world = GT_Mod.gregtechproxy.getThePlayer().worldObj; + listener = Minecraft.getMinecraft(); } + listener.addScheduledTask(() -> { + message.process(world); + }); + return null; } } diff --git a/src/main/java/gregtech/api/net/GT_Packet_Block_Event.java b/src/main/java/gregtech/api/net/GT_Packet_Block_Event.java new file mode 100644 index 00000000..23c90ca4 --- /dev/null +++ b/src/main/java/gregtech/api/net/GT_Packet_Block_Event.java @@ -0,0 +1,55 @@ +package gregtech.api.net; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; +import io.netty.buffer.ByteBuf; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +/** + * Used to transfer Block Events in a much better fashion + */ +public class GT_Packet_Block_Event extends GT_Packet { + private int mX, mZ; + private short mY; + private byte mID, mValue; + + public GT_Packet_Block_Event() {} + + public GT_Packet_Block_Event(int aX, short aY, int aZ, byte aID, byte aValue) { + mX = aX; + mY = aY; + mZ = aZ; + mID = aID; + mValue = aValue; + } + + @Override + public void encode(ByteBuf buf) { + buf.writeInt(mX); + buf.writeShort(mY); + buf.writeInt(mZ); + buf.writeByte(mID); + buf.writeByte(mValue); + } + + @Override + public void decode(ByteBuf buf) { + mX = buf.readInt(); + mY = buf.readShort(); + mZ = buf.readInt(); + mID = buf.readByte(); + mValue = buf.readByte(); + } + + @Override + public void process(World aWorld) { + if (aWorld != null) { + TileEntity tTileEntity = aWorld.getTileEntity(new BlockPos(mX, mY, mZ)); + if (tTileEntity != null) tTileEntity.receiveClientEvent(mID, mValue); + } + } +} \ No newline at end of file diff --git a/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java b/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java index ec025435..5baebcdc 100644 --- a/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java +++ b/src/main/java/gregtech/api/threads/GT_Runnable_Sound.java @@ -33,8 +33,7 @@ public class GT_Runnable_Sound implements Runnable { public void run() { SoundEvent soundEvent = SoundEvent.REGISTRY.getObject(mSoundLocation); if(soundEvent != null) { - PositionedSound sound = new PositionedSound(soundEvent, SoundCategory.BLOCKS) {}; - Minecraft.getMinecraft().getSoundHandler().playSound(sound); + mWorld.playSound((double)mX, (double)mY, (double)mZ, soundEvent, SoundCategory.BLOCKS, 1.0f, 1.0f, false); } } diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Machines.java b/src/main/java/gregtech/common/blocks/GT_Block_Machines.java index 09ead87a..6eeed06f 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Machines.java @@ -137,9 +137,15 @@ public class GT_Block_Machines extends GT_Generic_Block implements IDebugableBlo return false; } + /** + * NB: Vanilla redstone behavior is that wires will connect to redstone emitters but not consumers. + * Thus we only say we can connect if we are an emitter. (This is usually delegated to a cover behavior.) + * + */ @Override public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { - return true; + IGregTechTileEntity gregTechTileEntity = getGregTile(world, pos); + return gregTechTileEntity != null && gregTechTileEntity.canOutputRedstone((byte) side.getOpposite().getIndex()); } @Override @@ -356,7 +362,7 @@ public class GT_Block_Machines extends GT_Generic_Block implements IDebugableBlo public int getWeakPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { IGregTechTileEntity gregTechTileEntity = getGregTile(blockAccess, pos); if(gregTechTileEntity != null) { - gregTechTileEntity.getOutputRedstoneSignal((byte) side.getIndex()); + return gregTechTileEntity.getOutputRedstoneSignal((byte) side.getOpposite().getIndex()); } return 0; } @@ -365,7 +371,7 @@ public class GT_Block_Machines extends GT_Generic_Block implements IDebugableBlo public int getStrongPower(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { IGregTechTileEntity gregTechTileEntity = getGregTile(blockAccess, pos); if(gregTechTileEntity != null) { - gregTechTileEntity.getStrongOutputRedstoneSignal((byte) side.getIndex()); + return gregTechTileEntity.getStrongOutputRedstoneSignal((byte) side.getOpposite().getIndex()); } return 0; } diff --git a/src/main/java/gregtech/common/render/ItemRenderer.java b/src/main/java/gregtech/common/render/ItemRenderer.java index 5fd05052..a9832de3 100644 --- a/src/main/java/gregtech/common/render/ItemRenderer.java +++ b/src/main/java/gregtech/common/render/ItemRenderer.java @@ -294,11 +294,13 @@ public class ItemRenderer { public void renderItem(ItemStack item) { if(item.getItem() instanceof ItemBlock) { renderItem(item, 0); - } else { + } else if (item.getItem() instanceof GT_Generic_Item) { GT_Generic_Item generic_item = (GT_Generic_Item) item.getItem(); for(int i = 0; i < generic_item.getRenderPasses(item); i++) { renderItem(item, i); } + } else { + return; } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AdvMiner2.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AdvMiner2.java index 4784a015..9e685023 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AdvMiner2.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_AdvMiner2.java @@ -34,8 +34,9 @@ import java.util.List; public class GT_MetaTileEntity_AdvMiner2 extends GT_MetaTileEntity_MultiBlockBase { - private static final ItemStack mining_pipe = GT_ModHandler.getIC2Item(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.pipe, 1); - private static final ItemStack mining_pipe_tip = GT_ModHandler.getIC2Item(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.tip, 1); + private static final ItemStack mining_pipe_item = GT_ModHandler.getIC2Item(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.pipe, 1); + private static final IBlockState mining_pipe = GT_ModHandler.getIC2BlockState(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.pipe); + private static final IBlockState mining_pipe_tip = GT_ModHandler.getIC2BlockState(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.tip); private final ArrayList mMineList = new ArrayList(); @@ -74,15 +75,15 @@ public class GT_MetaTileEntity_AdvMiner2 extends GT_MetaTileEntity_MultiBlockBas @Override public boolean checkRecipe(ItemStack aStack) { - if (mInventory[1] == null || (mInventory[1].isItemEqual(mining_pipe) && mInventory[1].stackSize < mInventory[1].getMaxStackSize())) { + if (mInventory[1] == null || (mInventory[1].isItemEqual(mining_pipe_item) && mInventory[1].stackSize < mInventory[1].getMaxStackSize())) { ArrayList tItems = getStoredInputs(); for (ItemStack tStack : tItems) { - if (tStack.isItemEqual(mining_pipe)) { + if (tStack.isItemEqual(mining_pipe_item)) { tStack.stackSize--; if (tStack.stackSize < 1) { } if (mInventory[1] == null) { - mInventory[1] = mining_pipe; + mInventory[1] = mining_pipe_item; } else { mInventory[1].stackSize++; } @@ -139,7 +140,6 @@ public class GT_MetaTileEntity_AdvMiner2 extends GT_MetaTileEntity_MultiBlockBas List tDrops = new ArrayList(); Block tMineBlock = null; BlockPos mle = null; - int posX, posY, posZ, offX, offY, offZ; while ((tMineBlock==null || tMineBlock == Blocks.AIR) && !mMineList.isEmpty()) { mle = mMineList.get(0); mMineList.remove(0); @@ -147,26 +147,24 @@ public class GT_MetaTileEntity_AdvMiner2 extends GT_MetaTileEntity_MultiBlockBas } if (tMineBlock!=null && tMineBlock!=Blocks.AIR) { - posX = mle.getX() + getBaseMetaTileEntity().getXCoord(); - posY = mle.getY() + getBaseMetaTileEntity().getYCoord(); - posZ = mle.getZ() + getBaseMetaTileEntity().getZCoord(); - offX = mle.getX(); - offY = mle.getY(); - offZ = mle.getZ(); + BlockPos pos = new BlockPos(mle.getX() + getBaseMetaTileEntity().getXCoord(), + mle.getY() + getBaseMetaTileEntity().getYCoord(), + mle.getZ() + getBaseMetaTileEntity().getZCoord()); - IBlockState metadata = getBaseMetaTileEntity().getWorldObj().getBlockState(mle); - boolean silkTouch = tMineBlock.canSilkHarvest(getBaseMetaTileEntity().getWorldObj(), new BlockPos(posX, posY, posZ), metadata, null); + + IBlockState blockState = getBaseMetaTileEntity().getWorldObj().getBlockState(pos); + boolean silkTouch = tMineBlock.canSilkHarvest(getBaseMetaTileEntity().getWorldObj(), pos, blockState, null); if (silkTouch){ ItemStack IS = new ItemStack(tMineBlock); - IS.setItemDamage(metadata.getBlock().getMetaFromState(metadata)); + IS.setItemDamage(blockState.getBlock().getMetaFromState(blockState)); IS.stackSize=1; tDrops.add(IS); } else{ - tDrops = tMineBlock.getDrops(getBaseMetaTileEntity().getWorldObj(), new BlockPos(posX, posY, posZ), metadata, 1); + tDrops = tMineBlock.getDrops(getBaseMetaTileEntity().getWorldObj(), pos, blockState, 1); } - getBaseMetaTileEntity().getWorldObj().setBlockToAir(getBaseMetaTileEntity().getWorldPos().add(posX, posY, posZ)); + getBaseMetaTileEntity().getWorldObj().setBlockToAir(pos); if (!tDrops.isEmpty()) { ItemData tData = GT_OreDictUnificator.getItemData(tDrops.get(0).copy()); if (tData.mPrefix != OrePrefixes.crushed && tData.mMaterial.mMaterial != Materials.Oilsands) { @@ -225,7 +223,7 @@ public class GT_MetaTileEntity_AdvMiner2 extends GT_MetaTileEntity_MultiBlockBas private boolean moveOneDown() { if ((this.mInventory[1] == null) || (this.mInventory[1].stackSize < 1) - || (!GT_Utility.areStacksEqual(this.mInventory[1], mining_pipe))) { + || (!GT_Utility.areStacksEqual(this.mInventory[1], mining_pipe_item))) { stopMachine(); return false; } @@ -241,39 +239,38 @@ public class GT_MetaTileEntity_AdvMiner2 extends GT_MetaTileEntity_MultiBlockBas return false; } if (!(getBaseMetaTileEntity().getWorldObj().setBlockState( - new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, yHead - 1, getBaseMetaTileEntity().getZCoord() + zDir), - GT_Utility.getBlockFromStack(mining_pipe_tip).getDefaultState()))) { + new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, yHead - 1, getBaseMetaTileEntity().getZCoord() + zDir), mining_pipe_tip))) { stopMachine(); return false; } if (yHead != getBaseMetaTileEntity().getYCoord()) { getBaseMetaTileEntity().getWorldObj().setBlockState( - new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, yHead, getBaseMetaTileEntity().getZCoord() + zDir), - GT_Utility.getBlockFromStack(mining_pipe).getDefaultState()); + new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, yHead, getBaseMetaTileEntity().getZCoord() + zDir), mining_pipe); } getBaseMetaTileEntity().decrStackSize(1, 1); return true; } private int getYOfPumpHead() { - int xDir = EnumFacing.VALUES[getBaseMetaTileEntity().getBackFacing()].getFrontOffsetX(); - int zDir = EnumFacing.VALUES[getBaseMetaTileEntity().getBackFacing()].getFrontOffsetZ(); - int y = getBaseMetaTileEntity().getYCoord() - 1; - while (getBaseMetaTileEntity().getBlock(getBaseMetaTileEntity().getXCoord() + xDir, y, getBaseMetaTileEntity().getZCoord() + zDir) == GT_Utility.getBlockFromStack(mining_pipe)) { - y--; + BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(getBaseMetaTileEntity().getWorldPos()); + pos.move(EnumFacing.VALUES[getBaseMetaTileEntity().getBackFacing()]); + pos.move(EnumFacing.DOWN); + + while (getBaseMetaTileEntity().getBlockState(pos).equals(mining_pipe)) { + pos.move(EnumFacing.DOWN); } - if (y == getBaseMetaTileEntity().getYCoord() - 1) { - if (getBaseMetaTileEntity().getBlock(getBaseMetaTileEntity().getXCoord() + xDir, y, getBaseMetaTileEntity().getZCoord() + zDir) != GT_Utility.getBlockFromStack(mining_pipe_tip)) { - return y + 1; + if (pos.getY() == getBaseMetaTileEntity().getYCoord() - 1) { + if (!getBaseMetaTileEntity().getBlockState(pos).equals(mining_pipe_tip)) { + return pos.getY() + 1; } - } else if (getBaseMetaTileEntity().getBlock(getBaseMetaTileEntity().getXCoord() + xDir, y, getBaseMetaTileEntity().getZCoord() + zDir) != GT_Utility - .getBlockFromStack(mining_pipe_tip) && this.mInventory[1] != null && this.mInventory[1].stackSize > 0 && GT_Utility.areStacksEqual(this.mInventory[1], mining_pipe)) { - getBaseMetaTileEntity().getWorldObj().setBlockState( - new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, y, getBaseMetaTileEntity().getZCoord() + zDir), - GT_Utility.getBlockFromStack(mining_pipe_tip).getDefaultState()); + } else if (!getBaseMetaTileEntity().getBlockState(pos).equals(mining_pipe_tip) + && this.mInventory[1] != null + && this.mInventory[1].stackSize > 0 + && GT_Utility.areStacksEqual(this.mInventory[1], mining_pipe_item)) { + getBaseMetaTileEntity().getWorldObj().setBlockState(pos, mining_pipe_tip); getBaseMetaTileEntity().decrStackSize(0, 1); } - return y; + return pos.getY(); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Charcoal_Pit.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Charcoal_Pit.java index 18ea0a4f..3dbf7092 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Charcoal_Pit.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_Charcoal_Pit.java @@ -11,6 +11,7 @@ import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe; import gregtech.common.tools.GT_Tool; import gregtech.common.GT_Pollution; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; @@ -140,7 +141,7 @@ public class GT_MetaTileEntity_Charcoal_Pit extends GT_MetaTileEntity_MultiBlock if (aX + 1 < 6 && (isWoodLog(tBlock))) { if (!aList1.contains(new BlockPos(aX + 1, aY, aZ)) && (!aList2.contains(new BlockPos(aX + 1, aY, aZ)))) p1 = true; - } else if (!(tBlock == Blocks.DIRT || tBlock == Blocks.GRASS)) { + } else if (!isDirt(tBlock)) { return false; } @@ -148,7 +149,7 @@ public class GT_MetaTileEntity_Charcoal_Pit extends GT_MetaTileEntity_MultiBlock if (aX - 1 > -6 && (isWoodLog(tBlock))) { if (!aList1.contains(new BlockPos(aX - 1, aY, aZ)) && (!aList2.contains(new BlockPos(aX - 1, aY, aZ)))) p2 = true; - } else if (!(tBlock == Blocks.DIRT || tBlock == Blocks.GRASS)) { + } else if (!isDirt(tBlock)) { return false; } @@ -156,7 +157,7 @@ public class GT_MetaTileEntity_Charcoal_Pit extends GT_MetaTileEntity_MultiBlock if (aY + 1 < 1 && (isWoodLog(tBlock))) { if (!aList1.contains(new BlockPos(aX, aY + 1, aZ)) && (!aList2.contains(new BlockPos(aX, aY + 1, aZ)))) p3 = true; - } else if (!(tBlock == Blocks.DIRT || tBlock == Blocks.GRASS || (aX == 0 && aY == -1 && aZ == 0 && tBlock == GregTech_API.sBlockMachines))) { + } else if (!(isDirt(tBlock) || (aX == 0 && aY == -1 && aZ == 0 && tBlock.getBlock() == GregTech_API.sBlockMachines))) { return false; } @@ -164,7 +165,7 @@ public class GT_MetaTileEntity_Charcoal_Pit extends GT_MetaTileEntity_MultiBlock if (aY - 1 > -6 && (isWoodLog(tBlock))) { if (!aList1.contains(new BlockPos(aX, aY - 1, aZ)) && (!aList2.contains(new BlockPos(aX, aY - 1, aZ)))) p4 = true; - } else if (tBlock != Blocks.BRICK_BLOCK) { + } else if (tBlock.getBlock() != Blocks.BRICK_BLOCK) { return false; } @@ -172,7 +173,7 @@ public class GT_MetaTileEntity_Charcoal_Pit extends GT_MetaTileEntity_MultiBlock if (aZ + 1 < 6 && (isWoodLog(tBlock))) { if (!aList1.contains(new BlockPos(aX, aY, aZ + 1)) && (!aList2.contains(new BlockPos(aX, aY, aZ + 1)))) p5 = true; - } else if (!(tBlock == Blocks.DIRT || tBlock == Blocks.GRASS)) { + } else if (!isDirt(tBlock)) { return false; } @@ -180,7 +181,7 @@ public class GT_MetaTileEntity_Charcoal_Pit extends GT_MetaTileEntity_MultiBlock if (aZ - 1 > -6 && (isWoodLog(tBlock))) { if (!aList1.contains(new BlockPos(aX, aY, aZ - 1)) && (!aList2.contains(new BlockPos(aX, aY, aZ - 1)))) p6 = true; - } else if (!(tBlock == Blocks.DIRT || tBlock == Blocks.GRASS)) { + } else if (!isDirt(tBlock)) { return false; } aList1.add(new BlockPos(aX, aY, aZ)); @@ -200,6 +201,11 @@ public class GT_MetaTileEntity_Charcoal_Pit extends GT_MetaTileEntity_MultiBlock (log.getMaterial() == Material.WOOD); } + private boolean isDirt(IBlockState dirt) { + Block b = dirt.getBlock(); + return (b == Blocks.DIRT || b == Blocks.GRASS); + } + public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack aStack) { mWrench = true; mScrewdriver = true; diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrill.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrill.java index 4bc30c9e..e2cb8bae 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrill.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_OilDrill.java @@ -12,6 +12,7 @@ import gregtech.api.util.GT_ModHandler; import gregtech.api.util.GT_Utility; import ic2.core.block.machine.BlockMiningPipe; import ic2.core.ref.BlockName; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; @@ -23,8 +24,9 @@ import java.util.ArrayList; public class GT_MetaTileEntity_OilDrill extends GT_MetaTileEntity_MultiBlockBase { - private static final ItemStack mining_pipe = GT_ModHandler.getIC2Item(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.pipe, 1); - private static final ItemStack mining_pipe_tip = GT_ModHandler.getIC2Item(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.tip, 1); + private static final ItemStack mining_pipe_item = GT_ModHandler.getIC2Item(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.pipe, 1); + private static final IBlockState mining_pipe = GT_ModHandler.getIC2BlockState(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.pipe); + private static final IBlockState mining_pipe_tip = GT_ModHandler.getIC2BlockState(BlockName.mining_pipe, BlockMiningPipe.MiningPipeType.tip); private boolean completedCycle = false; @@ -61,10 +63,10 @@ public class GT_MetaTileEntity_OilDrill extends GT_MetaTileEntity_MultiBlockBase @Override public boolean checkRecipe(ItemStack aStack) { - if (mInventory[1] == null || (mInventory[1].isItemEqual(mining_pipe) && mInventory[1].stackSize < mInventory[1].getMaxStackSize())) { + if (mInventory[1] == null || (mInventory[1].isItemEqual(mining_pipe_item) && mInventory[1].stackSize < mInventory[1].getMaxStackSize())) { ArrayList tItems = getStoredInputs(); for (ItemStack tStack : tItems) { - if (tStack.isItemEqual(mining_pipe)) { + if (tStack.isItemEqual(mining_pipe_item)) { if (tStack.stackSize < 2) { tStack = null; } else { @@ -73,7 +75,7 @@ public class GT_MetaTileEntity_OilDrill extends GT_MetaTileEntity_MultiBlockBase } if (mInventory[1] == null) { - mInventory[1] = mining_pipe; + mInventory[1] = mining_pipe_item; } else { mInventory[1].stackSize++; } @@ -126,7 +128,7 @@ public class GT_MetaTileEntity_OilDrill extends GT_MetaTileEntity_MultiBlockBase private boolean moveOneDown() { if ((this.mInventory[1] == null) || (this.mInventory[1].stackSize < 1) - || (!GT_Utility.areStacksEqual(this.mInventory[1], mining_pipe))) { + || (!GT_Utility.areStacksEqual(this.mInventory[1], mining_pipe_item))) { return false; } int xDir = EnumFacing.VALUES[getBaseMetaTileEntity().getBackFacing()].getFrontOffsetX(); @@ -139,38 +141,37 @@ public class GT_MetaTileEntity_OilDrill extends GT_MetaTileEntity_MultiBlockBase return false; } if (!(getBaseMetaTileEntity().getWorldObj().setBlockState( - new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, yHead - 1, getBaseMetaTileEntity().getZCoord() + zDir), - GT_Utility.getBlockFromStack(mining_pipe_tip).getDefaultState()))) { + new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, yHead - 1, getBaseMetaTileEntity().getZCoord() + zDir), mining_pipe_tip))) { return false; } if (yHead != getBaseMetaTileEntity().getYCoord()) { getBaseMetaTileEntity().getWorldObj().setBlockState( - new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, yHead, getBaseMetaTileEntity().getZCoord() + zDir), - GT_Utility.getBlockFromStack(mining_pipe).getDefaultState()); + new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, yHead, getBaseMetaTileEntity().getZCoord() + zDir), mining_pipe); } getBaseMetaTileEntity().decrStackSize(1, 1); return true; } private int getYOfPumpHead() { - int xDir = EnumFacing.VALUES[getBaseMetaTileEntity().getBackFacing()].getFrontOffsetX(); - int zDir = EnumFacing.VALUES[getBaseMetaTileEntity().getBackFacing()].getFrontOffsetZ(); - int y = getBaseMetaTileEntity().getYCoord() - 1; - while (getBaseMetaTileEntity().getBlock(getBaseMetaTileEntity().getXCoord() + xDir, y, getBaseMetaTileEntity().getZCoord() + zDir) == GT_Utility.getBlockFromStack(mining_pipe)) { - y--; + BlockPos.MutableBlockPos pos = new BlockPos.MutableBlockPos(getBaseMetaTileEntity().getWorldPos()); + pos.move(EnumFacing.VALUES[getBaseMetaTileEntity().getBackFacing()]); + pos.move(EnumFacing.DOWN); + + while (getBaseMetaTileEntity().getBlockState(pos).equals(mining_pipe)) { + pos.move(EnumFacing.DOWN); } - if (y == getBaseMetaTileEntity().getYCoord() - 1) { - if (getBaseMetaTileEntity().getBlock(getBaseMetaTileEntity().getXCoord() + xDir, y, getBaseMetaTileEntity().getZCoord() + zDir) != GT_Utility.getBlockFromStack(mining_pipe_tip)) { - return y + 1; + if (pos.getY() == getBaseMetaTileEntity().getYCoord() - 1) { + if (!getBaseMetaTileEntity().getBlockState(pos).equals(mining_pipe_tip)) { + return pos.getY() + 1; } - } else if (getBaseMetaTileEntity().getBlock(getBaseMetaTileEntity().getXCoord() + xDir, y, getBaseMetaTileEntity().getZCoord() + zDir) != GT_Utility - .getBlockFromStack(mining_pipe_tip) && this.mInventory[1] != null && this.mInventory[1].stackSize > 0 && GT_Utility.areStacksEqual(this.mInventory[1], mining_pipe)) { - getBaseMetaTileEntity().getWorldObj().setBlockState( - new BlockPos(getBaseMetaTileEntity().getXCoord() + xDir, y, getBaseMetaTileEntity().getZCoord() + zDir), - GT_Utility.getBlockFromStack(mining_pipe_tip).getDefaultState()); + } else if (!getBaseMetaTileEntity().getBlockState(pos).equals(mining_pipe_tip) + && this.mInventory[1] != null + && this.mInventory[1].stackSize > 0 + && GT_Utility.areStacksEqual(this.mInventory[1], mining_pipe_item)) { + getBaseMetaTileEntity().getWorldObj().setBlockState(pos, mining_pipe_tip); getBaseMetaTileEntity().decrStackSize(0, 1); } - return y; + return pos.getY(); } @Override