From d490759e8defa05e8ce0b994086d43fb56b28fb7 Mon Sep 17 00:00:00 2001 From: Dragon2488 Date: Thu, 15 Sep 2016 18:28:52 +0700 Subject: [PATCH] Lightning fix, black blocks on break attempt fix --- src/main/java/gregtech/GT_Mod.java | 25 +--- src/main/java/gregtech/api/enums/Dyes.java | 11 +- .../java/gregtech/api/enums/GT_Values.java | 4 +- .../java/gregtech/api/enums/Textures.java | 8 +- .../gregtech/api/interfaces/ITexture.java | 2 +- .../gregtech/api/items/GT_Generic_Block.java | 24 ++-- .../metatileentity/BaseMetaPipeEntity.java | 26 ++-- .../metatileentity/BaseMetaTileEntity.java | 33 ++--- .../metatileentity/BaseMetaTileEntityUE.java | 98 --------------- .../api/metatileentity/BaseTileEntity.java | 3 +- src/main/java/gregtech/api/net/GT_Packet.java | 35 +++--- .../gregtech/api/net/GT_PacketHandler.java | 46 +++++++ .../api/net/GT_Packet_Block_Event.java | 59 --------- .../gregtech/api/net/GT_Packet_Sound.java | 46 ++++--- .../api/net/GT_Packet_TileEntity.java | 49 +++++--- .../gregtech/api/net/IGT_NetworkHandler.java | 15 --- .../api/objects/GT_CopiedBlockTexture.java | 65 +++++----- .../gregtech/api/objects/GT_MultiTexture.java | 9 +- .../api/objects/GT_RenderedTexture.java | 10 +- .../gregtech/api/objects/GT_SidedTexture.java | 17 +-- .../java/gregtech/api/util/GT_Utility.java | 13 +- src/main/java/gregtech/common/GT_Network.java | 98 --------------- .../gregtech/common/GT_Worldgenerator.java | 17 ++- .../common/blocks/GT_Block_Casings1.java | 3 +- .../common/blocks/GT_Block_Casings4.java | 4 +- .../blocks/GT_Block_Casings_Abstract.java | 17 +-- .../common/blocks/GT_Block_Concretes.java | 9 +- .../common/blocks/GT_Block_Machines.java | 14 +-- .../common/blocks/GT_Block_Ores_Abstract.java | 12 -- .../common/blocks/GT_Block_Reinforced.java | 82 ------------- .../blocks/GT_Block_Stones_Abstract.java | 10 -- .../common/blocks/GT_Packet_Ores.java | 116 ++++++++++++------ .../common/blocks/GT_TickHandler_Ores.java | 30 +++-- .../common/blocks/GT_TileEntity_Ores.java | 8 -- .../render/newblocks/BlockRenderer.java | 18 ++- .../render/newblocks/IBlockIconProvider.java | 1 - .../common/render/newblocks/RenderUtil.java | 22 ++-- 37 files changed, 351 insertions(+), 708 deletions(-) delete mode 100644 src/main/java/gregtech/api/metatileentity/BaseMetaTileEntityUE.java create mode 100644 src/main/java/gregtech/api/net/GT_PacketHandler.java delete mode 100644 src/main/java/gregtech/api/net/GT_Packet_Block_Event.java delete mode 100644 src/main/java/gregtech/api/net/IGT_NetworkHandler.java delete mode 100644 src/main/java/gregtech/common/GT_Network.java diff --git a/src/main/java/gregtech/GT_Mod.java b/src/main/java/gregtech/GT_Mod.java index b592c59a..4c13b5d9 100644 --- a/src/main/java/gregtech/GT_Mod.java +++ b/src/main/java/gregtech/GT_Mod.java @@ -1,5 +1,6 @@ package gregtech; +import gregtech.api.net.GT_PacketHandler; import gregtech.api.objects.GT_ItemStack; import gregtech.common.*; import ic2.api.recipe.IMachineRecipeManager; @@ -95,7 +96,7 @@ public class GT_Mod implements IGT_Mod { } GT_Values.GT = this; GT_Values.DW = new GT_DummyWorld(); - GT_Values.NW = new GT_Network(); + GT_Values.NW = new GT_PacketHandler(); GregTech_API.sRecipeAdder = GT_Values.RA = new GT_RecipeAdder(); Textures.BlockIcons.VOID.name(); @@ -108,28 +109,6 @@ public class GT_Mod implements IGT_Mod { return; } - - /*final Thread currentThread = Thread.currentThread(); - new Thread(new Runnable() { - long currentMills = 0; - - @Override - public void run() { - while (true) { - if (System.currentTimeMillis() - currentMills > 100000) { - currentMills = System.currentTimeMillis(); - System.out.println("Last stack trace of " + currentThread.getName() + ": "); - StackTraceElement[] trace = currentThread.getStackTrace(); - if (trace.length > 10) { - for (int i = 0; i < 10; i++) { - System.out.println(trace[i].toString()); - } - } - } - } - } - }).start();*/ - GT_Log.out.println("GT_Mod: Replacing IC2 recipes managers"); try { for (Field f : Recipes.class.getFields()) { diff --git a/src/main/java/gregtech/api/enums/Dyes.java b/src/main/java/gregtech/api/enums/Dyes.java index c305262f..41f1da9e 100644 --- a/src/main/java/gregtech/api/enums/Dyes.java +++ b/src/main/java/gregtech/api/enums/Dyes.java @@ -37,9 +37,9 @@ public enum Dyes implements IColorModulationContainer { */ CABLE_INSULATION(-1, 64, 64, 64, "Cable Insulation"), CONSTRUCTION_FOAM(-1, 64, 64, 64, "Construction Foam"), - MACHINE_METAL(-1, 220, 220, 255, "Machine Metal"); + MACHINE_METAL(-1, 230, 230, 255, "Machine Metal"); - public static final Dyes VALUES[] = {dyeBlack, dyeRed, dyeGreen, dyeBrown, dyeBlue, dyePurple, dyeCyan, dyeLightGray, dyeGray, dyePink, dyeLime, dyeYellow, dyeLightBlue, dyeMagenta, dyeOrange, dyeWhite}; + public static final Dyes VALUES[] = {MACHINE_METAL, dyeRed, dyeGreen, dyeBrown, dyeBlue, dyePurple, dyeCyan, dyeLightGray, dyeGray, dyePink, dyeLime, dyeYellow, dyeLightBlue, dyeMagenta, dyeOrange, dyeWhite}; public final byte mIndex; public final String mName; @@ -57,8 +57,13 @@ public enum Dyes implements IColorModulationContainer { return _NULL; } + public static short[] getModulation(int aColor, Dyes aDefaultModulation) { + return getModulation(aColor, aDefaultModulation.mRGBa); + } + public static short[] getModulation(int aColor, short[] aDefaultModulation) { - if (aColor >= 0 && aColor < 16) return VALUES[aColor].mRGBa; + if (aColor >= 0 && aColor < VALUES.length) + return VALUES[aColor].mRGBa; return aDefaultModulation; } diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java index 496357e1..a69756e6 100644 --- a/src/main/java/gregtech/api/enums/GT_Values.java +++ b/src/main/java/gregtech/api/enums/GT_Values.java @@ -2,7 +2,7 @@ package gregtech.api.enums; import gregtech.api.interfaces.internal.IGT_Mod; import gregtech.api.interfaces.internal.IGT_RecipeAdder; -import gregtech.api.net.IGT_NetworkHandler; +import gregtech.api.net.GT_PacketHandler; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.fluids.FluidStack; @@ -101,7 +101,7 @@ public class GT_Values { /** * For Internal Usage (Network) */ - public static IGT_NetworkHandler NW; + public static GT_PacketHandler NW; /** * Not really Constants, but they set using the Config and therefore should be constant (those are for the Debug Mode) */ diff --git a/src/main/java/gregtech/api/enums/Textures.java b/src/main/java/gregtech/api/enums/Textures.java index 8a342afb..725438c5 100644 --- a/src/main/java/gregtech/api/enums/Textures.java +++ b/src/main/java/gregtech/api/enums/Textures.java @@ -532,12 +532,16 @@ public class Textures { static { for (byte i = 0; i < MACHINE_CASINGS.length; i++) for (byte j = 0; j < MACHINE_CASINGS[i].length; j++) - MACHINE_CASINGS[i][j] = new GT_SidedTexture(MACHINECASINGS_BOTTOM[i], MACHINECASINGS_TOP[i], MACHINECASINGS_SIDE[i], Dyes.getModulation(j - 1, Dyes.MACHINE_METAL.mRGBa)); + MACHINE_CASINGS[i][j] = new GT_SidedTexture( + MACHINECASINGS_BOTTOM[i], + MACHINECASINGS_TOP[i], + MACHINECASINGS_SIDE[i], + Dyes.MACHINE_METAL.mRGBa); } protected TextureAtlasSprite mIcon; - private BlockIcons() { + BlockIcons() { GregTech_API.sGTBlockIconload.add(this); } diff --git a/src/main/java/gregtech/api/interfaces/ITexture.java b/src/main/java/gregtech/api/interfaces/ITexture.java index d25a5899..48833389 100644 --- a/src/main/java/gregtech/api/interfaces/ITexture.java +++ b/src/main/java/gregtech/api/interfaces/ITexture.java @@ -9,7 +9,7 @@ import java.util.List; public interface ITexture { - public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOffset); + public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, float offset); public boolean isValidTexture(); } \ No newline at end of file diff --git a/src/main/java/gregtech/api/items/GT_Generic_Block.java b/src/main/java/gregtech/api/items/GT_Generic_Block.java index 17c36843..9fcdef96 100644 --- a/src/main/java/gregtech/api/items/GT_Generic_Block.java +++ b/src/main/java/gregtech/api/items/GT_Generic_Block.java @@ -21,6 +21,8 @@ import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; import net.minecraftforge.fml.common.registry.GameRegistry; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import static gregtech.api.enums.GT_Values.W; @@ -36,13 +38,6 @@ public abstract class GT_Generic_Block extends Block { setUnlocalizedName(mUnlocalizedName = aName); GameRegistry.registerBlock(this, aItemClass, getUnlocalizedName()); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + "." + W + ".name", "Any Sub Block of this one"); - setLightLevel(2); - translucent = true; - } - - @Override - public boolean isOpaqueCube(IBlockState state) { - return false; } @Override @@ -76,17 +71,14 @@ public abstract class GT_Generic_Block extends Block { } @Override + public boolean isOpaqueCube(IBlockState state) { + return false; + } + + @Override + @SideOnly(Side.CLIENT) public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.CUTOUT; } - @Override - public EnumBlockRenderType getRenderType(IBlockState state) { - StackTraceElement[] trace = Thread.currentThread().getStackTrace(); - if(trace[3].getMethodName().equals("renderBlockDamage")) { - return EnumBlockRenderType.INVISIBLE; - //TODO FIX ME PLEASE - } - return EnumBlockRenderType.MODEL; - } } \ No newline at end of file diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java index 0eb1a28f..04b0815b 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaPipeEntity.java @@ -189,24 +189,19 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE mMetaTileEntity.setBaseMetaTileEntity(this); } - if (isServerSide()) { - if (mTickTimer % 10 == 0) { - if (mSendClientData) { - NW.sendPacketToAllPlayersInRange(worldObj, - new GT_Packet_TileEntity( - getXCoord(), getYCoord(), getZCoord(), mID, - mCoverSides[0], mCoverSides[1], mCoverSides[2], mCoverSides[3], mCoverSides[4], mCoverSides[5], - oTextureData = mConnections, oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, - oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | - ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) - | ((mSidedRedstone[5] > 0) ? 32 : 0)), oColor = mColor), getXCoord(), getZCoord()); - mSendClientData = false; - } - } + if (isServerSide() && mTickTimer % 10 == 0) { + NW.sendToAllAround(worldObj, + new GT_Packet_TileEntity( + getXCoord(), getYCoord(), getZCoord(), mID, + mCoverSides[0], mCoverSides[1], mCoverSides[2], mCoverSides[3], mCoverSides[4], mCoverSides[5], + oTextureData = mConnections, oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, + oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | + ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) + | ((mSidedRedstone[5] > 0) ? 32 : 0)), oColor = mColor, true), + getXCoord(), getYCoord(), getZCoord()); } long tTime = System.currentTimeMillis(); - for (int tCode = 0; hasValidMetaTileEntity() && tCode >= 0; ) { try { switch (tCode) { @@ -236,6 +231,7 @@ public class BaseMetaPipeEntity extends BaseTileEntity implements IGregTechTileE causeChunkUpdate(); mNeedsUpdate = false; } + } case 2: case 3: diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java index 6dcb4efc..aa026bba 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntity.java @@ -278,20 +278,18 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE mRunningThroughTick = true; long tTime = System.currentTimeMillis(); - if (isServerSide()) { - if (mTickTimer % 20 == 0) { - NW.sendPacketToAllPlayersInRange(worldObj, new GT_Packet_TileEntity( - getXCoord(), getYCoord(), getZCoord(), mID, - mCoverSides[0], mCoverSides[1], mCoverSides[2], - mCoverSides[3], mCoverSides[4], mCoverSides[5], - oTextureData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | - (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0)), - oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, - oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | - ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | - ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)), oColor = mColor), - getXCoord(), getZCoord()); - } + if (isServerSide() && mTickTimer % 10 == 0) { + NW.sendToAllAround(worldObj, new GT_Packet_TileEntity( + getXCoord(), getYCoord(), getZCoord(), mID, + mCoverSides[0], mCoverSides[1], mCoverSides[2], + mCoverSides[3], mCoverSides[4], mCoverSides[5], + oTextureData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | + (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0)), + oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, + oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | + ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | + ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)), oColor = mColor, false), + getXCoord(), getYCoord(), getZCoord()); } for (int tCode = 0; hasValidMetaTileEntity() && tCode >= 0; ) { @@ -530,13 +528,6 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE case 15: tCode++; if (isServerSide()) { - if (mTickTimer % 10 == 0) { - if (mSendClientData) { - NW.sendPacketToAllPlayersInRange(worldObj, new GT_Packet_TileEntity(getXCoord(), (short) getYCoord(), getZCoord(), mID, mCoverSides[0], mCoverSides[1], mCoverSides[2], mCoverSides[3], mCoverSides[4], mCoverSides[5], oTextureData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0)), oUpdateData = hasValidMetaTileEntity() ? mMetaTileEntity.getUpdateData() : 0, oRedstoneData = (byte) (((mSidedRedstone[0] > 0) ? 1 : 0) | ((mSidedRedstone[1] > 0) ? 2 : 0) | ((mSidedRedstone[2] > 0) ? 4 : 0) | ((mSidedRedstone[3] > 0) ? 8 : 0) | ((mSidedRedstone[4] > 0) ? 16 : 0) | ((mSidedRedstone[5] > 0) ? 32 : 0)), oColor = mColor), getXCoord(), getZCoord()); - mSendClientData = false; - } - } - if (mTickTimer > 10) { byte tData = (byte) ((mFacing & 7) | (mActive ? 8 : 0) | (mRedstone ? 16 : 0) | (mLockUpgrade ? 32 : 0)); if (tData != oTextureData) sendBlockEvent((byte) 0, oTextureData = tData); diff --git a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntityUE.java b/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntityUE.java deleted file mode 100644 index 26388bd1..00000000 --- a/src/main/java/gregtech/api/metatileentity/BaseMetaTileEntityUE.java +++ /dev/null @@ -1,98 +0,0 @@ -package gregtech.api.metatileentity; - - -/** - * NEVER INCLUDE THIS FILE IN YOUR MOD!!! - *

- * This file contains all the needed 'implements' of the Interfaces for the Universal Electricity Stuff. - *

- * I am using the BC3 Ratio, since that is a constant in comparison to ICĀ² Energy (1 MJ is always 2,5 EU). - */ -public class BaseMetaTileEntityUE extends BaseMetaTileEntity /*implements IUETileEntity*/ { - public BaseMetaTileEntityUE() { - super(); - } - /* - @Override - public void updateStatus() { - super.updateStatus(); - } - - @Override - public void chargeItem(ItemStack aStack) { - super.chargeItem(aStack); - float tEnergy = ElectricItemHelper.chargeItem(aStack, (float)(getOfferedEnergy() * (Compatibility.BC3_RATIO * 0.4F))); - if (tEnergy > 0) decreaseStoredEU((int)(tEnergy / (Compatibility.BC3_RATIO * 0.4F)) + 1, true); - } - - @Override - public void dischargeItem(ItemStack aStack) { - super.dischargeItem(aStack); - float tEnergy = ElectricItemHelper.dischargeItem(aStack, (float)(demandedEnergyUnits() * (Compatibility.BC3_RATIO * 0.4F))); - if (tEnergy > 0) increaseStoredEnergyUnits((int)(tEnergy / (Compatibility.BC3_RATIO * 0.4F)), true); - } - - @Override - public float receiveElectricity(ForgeDirection aSide, ElectricityPack aPacket, boolean doReceive) { - if (!getUEConsumingSides().contains(aSide)) return 0; - int aInserted = (int)(aPacket.getWatts()/(Compatibility.BC3_RATIO * 0.4F)); - if (doReceive) return injectEnergyUnits((byte)aSide.ordinal(), aInserted, 1) ? aInserted : 0; - return getEUCapacity() - getStoredEU() >= aInserted ? aInserted : 0; - } - - @Override - public ElectricityPack provideElectricity(ForgeDirection aSide, ElectricityPack aRequested, boolean doProvide) { - if (!getUEProducingSides().contains(aSide)) return null; - int aExtracted = (int)getOfferedEnergy(); - if (doProvide) return aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F) >= getOfferedEnergy() ? decreaseStoredEU(aExtracted, false) ? new ElectricityPack(aExtracted * (Compatibility.BC3_RATIO * 0.4F), 1) : null : decreaseStoredEU((int)(aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F)), false) ? new ElectricityPack((int)(aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F)) * (Compatibility.BC3_RATIO * 0.4F), 1) : null; - return aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F) >= getOfferedEnergy() ? new ElectricityPack(aExtracted * (Compatibility.BC3_RATIO * 0.4F), 1) : new ElectricityPack((int)(aRequested.getWatts()/(Compatibility.BC3_RATIO * 0.4F)) * (Compatibility.BC3_RATIO * 0.4F), 1); - } - - @Override - public float getRequest(ForgeDirection aSide) { - if (!getUEConsumingSides().contains(aSide)) return 0; - return (float)(demandedEnergyUnits() * (Compatibility.BC3_RATIO * 0.4F)); - } - - @Override - public float getProvide(ForgeDirection aSide) { - if (!getUEProducingSides().contains(aSide)) return 0; - return (float)(getOfferedEnergy() * (Compatibility.BC3_RATIO * 0.4F)); - } - - @Override - public float getVoltage() { - return (float)(getOfferedEnergy() * (Compatibility.BC3_RATIO * 0.4F)); - } - - @Override - public boolean canConnect(ForgeDirection aSide) { - return getUEProducingSides().contains(aSide) || getUEConsumingSides().contains(aSide); - } - - private EnumSet getUEConsumingSides() { - EnumSet rSides = EnumSet.noneOf(ForgeDirection.class); - for (byte i = 0; i < 6; i++) { - if (inputEnergyFrom(i)) { - Object tTileEntity = getTileEntityAtSide(i); - if (tTileEntity != null && tTileEntity instanceof IConductor) { - rSides.add(ForgeDirection.getOrientation(i)); - } - } - } - return rSides; - } - - private EnumSet getUEProducingSides() { - EnumSet rSides = EnumSet.noneOf(ForgeDirection.class); - for (byte i = 0; i < 6; i++) { - if (outputsEnergyTo(i)) { - Object tTileEntity = getTileEntityAtSide(i); - if (tTileEntity != null && tTileEntity instanceof IConductor) { - rSides.add(ForgeDirection.getOrientation(i)); - } - } - } - return rSides; - }*/ -} \ No newline at end of file diff --git a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java index 96da0a7c..72ae1e54 100644 --- a/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java +++ b/src/main/java/gregtech/api/metatileentity/BaseTileEntity.java @@ -2,7 +2,6 @@ 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; @@ -425,7 +424,7 @@ 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.sendPacketToAllPlayersInRange(worldObj, new GT_Packet_Block_Event(getXCoord(), (short) getYCoord(), getZCoord(), aID, aValue), getXCoord(), getZCoord()); } private boolean crossedChunkBorder(int aX, int aZ) { diff --git a/src/main/java/gregtech/api/net/GT_Packet.java b/src/main/java/gregtech/api/net/GT_Packet.java index 6fdd013d..fc0aa858 100644 --- a/src/main/java/gregtech/api/net/GT_Packet.java +++ b/src/main/java/gregtech/api/net/GT_Packet.java @@ -1,29 +1,32 @@ package gregtech.api.net; -import com.google.common.io.ByteArrayDataInput; -import net.minecraft.world.IBlockAccess; +import io.netty.buffer.ByteBuf; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; -public abstract class GT_Packet { - public GT_Packet(boolean aIsReference) { - // +public abstract class GT_Packet implements IMessage { + + public GT_Packet() {} + + @Override + public final void fromBytes(ByteBuf buf) { + decode(buf); + } + + @Override + public final void toBytes(ByteBuf buf) { + encode(buf); } /** - * I use constant IDs instead of Dynamic ones, since that is much more fail safe - * - * @return a Packet ID for this Class + * @return encoded byte Stream */ - public abstract byte getPacketID(); + public abstract void encode(ByteBuf buf); /** * @return encoded byte Stream */ - public abstract byte[] encode(); + public abstract void decode(ByteBuf buf); - /** - * @return encoded byte Stream - */ - public abstract GT_Packet decode(ByteArrayDataInput aData); - - public abstract void process(IBlockAccess aWorld); + public abstract void process(World world); } \ No newline at end of file diff --git a/src/main/java/gregtech/api/net/GT_PacketHandler.java b/src/main/java/gregtech/api/net/GT_PacketHandler.java new file mode 100644 index 00000000..85a26b1b --- /dev/null +++ b/src/main/java/gregtech/api/net/GT_PacketHandler.java @@ -0,0 +1,46 @@ +package gregtech.api.net; + +import gregtech.common.blocks.GT_Packet_Ores; +import net.minecraft.world.World; +import net.minecraftforge.fml.client.FMLClientHandler; +import net.minecraftforge.fml.common.network.NetworkRegistry; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import net.minecraftforge.fml.relauncher.Side; + +public class GT_PacketHandler extends SimpleNetworkWrapper { + + public GT_PacketHandler() { + super("gregtech_network"); + registerMessage(0, GT_Packet_TileEntity.class, Side.CLIENT); + registerMessage(1, GT_Packet_Ores.class, Side.CLIENT); + registerMessage(2, GT_Packet_Sound.class, Side.CLIENT); + } + + public void registerMessage(int discriminator, Class packet, Side handleSide) { + if(GT_Packet.class.isAssignableFrom(packet)) { + registerMessage(GT_MessageHandler.class, packet, discriminator, handleSide); + } else { + throw new IllegalArgumentException("Tried to register non-packet class " + packet.getName()); + } + } + + public void sendToAllAround(World world, GT_Packet packet, int x, int y, int z) { + sendToAllAround(packet, new NetworkRegistry.TargetPoint(world.provider.getDimension(), x, y, z, 64)); + } + + public static class GT_MessageHandler implements IMessageHandler { + + @Override + public GT_Packet onMessage(GT_Packet message, MessageContext ctx) { + if(ctx.side == Side.SERVER) { + message.process(ctx.getServerHandler().playerEntity.worldObj); + } else { + message.process(FMLClientHandler.instance().getWorldClient()); + } + 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 deleted file mode 100644 index d539eef4..00000000 --- a/src/main/java/gregtech/api/net/GT_Packet_Block_Event.java +++ /dev/null @@ -1,59 +0,0 @@ -package gregtech.api.net; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IBlockAccess; - -/** - * 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() { - super(true); - } - - public GT_Packet_Block_Event(int aX, short aY, int aZ, byte aID, byte aValue) { - super(false); - mX = aX; - mY = aY; - mZ = aZ; - mID = aID; - mValue = aValue; - } - - @Override - public byte[] encode() { - ByteArrayDataOutput tOut = ByteStreams.newDataOutput(10); - tOut.writeInt(mX); - tOut.writeShort(mY); - tOut.writeInt(mZ); - tOut.writeByte(mID); - tOut.writeByte(mValue); - return tOut.toByteArray(); - } - - @Override - public GT_Packet decode(ByteArrayDataInput aData) { - return new GT_Packet_Block_Event(aData.readInt(), aData.readShort(), aData.readInt(), aData.readByte(), aData.readByte()); - } - - @Override - public void process(IBlockAccess aWorld) { - if (aWorld != null) { - TileEntity tTileEntity = aWorld.getTileEntity(new BlockPos(mX, mY, mZ)); - if (tTileEntity != null) tTileEntity.receiveClientEvent(mID, mValue); - } - } - - @Override - public byte getPacketID() { - return 2; - } -} \ No newline at end of file diff --git a/src/main/java/gregtech/api/net/GT_Packet_Sound.java b/src/main/java/gregtech/api/net/GT_Packet_Sound.java index 5490d0d3..44692aab 100644 --- a/src/main/java/gregtech/api/net/GT_Packet_Sound.java +++ b/src/main/java/gregtech/api/net/GT_Packet_Sound.java @@ -1,23 +1,20 @@ package gregtech.api.net; -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteArrayDataOutput; -import com.google.common.io.ByteStreams; import gregtech.api.util.GT_Utility; +import io.netty.buffer.ByteBuf; import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; +import net.minecraftforge.fml.common.network.ByteBufUtils; public class GT_Packet_Sound extends GT_Packet { - private int mX, mZ; - private short mY; + + private int mX, mZ, mY; private String mSoundName; private float mSoundStrength, mSoundPitch; - public GT_Packet_Sound() { - super(true); - } + public GT_Packet_Sound() {} public GT_Packet_Sound(String aSoundName, float aSoundStrength, float aSoundPitch, int aX, short aY, int aZ) { - super(false); mX = aX; mY = aY; mZ = aZ; @@ -27,29 +24,28 @@ public class GT_Packet_Sound extends GT_Packet { } @Override - public byte[] encode() { - ByteArrayDataOutput tOut = ByteStreams.newDataOutput(10); - tOut.writeUTF(mSoundName); - tOut.writeFloat(mSoundStrength); - tOut.writeFloat(mSoundPitch); - tOut.writeInt(mX); - tOut.writeShort(mY); - tOut.writeInt(mZ); - return tOut.toByteArray(); + public void encode(ByteBuf buf) { + ByteBufUtils.writeUTF8String(buf, mSoundName); + buf.writeFloat(mSoundStrength); + buf.writeFloat(mSoundPitch); + buf.writeInt(mX); + buf.writeShort(mY); + buf.writeInt(mZ); } @Override - public GT_Packet decode(ByteArrayDataInput aData) { - return new GT_Packet_Sound(aData.readUTF(), aData.readFloat(), aData.readFloat(), aData.readInt(), aData.readShort(), aData.readInt()); + public void decode(ByteBuf buf) { + mSoundName = ByteBufUtils.readUTF8String(buf); + mSoundStrength = buf.readFloat(); + mSoundPitch = buf.readFloat(); + mX = buf.readInt(); + mY = buf.readShort(); + mZ = buf.readInt(); } @Override - public void process(IBlockAccess aWorld) { + public void process(World aWorld) { GT_Utility.doSoundAtClient(mSoundName, 1, mSoundStrength, mSoundPitch, mX, mY, mZ); } - @Override - public byte getPacketID() { - return 1; - } } \ No newline at end of file diff --git a/src/main/java/gregtech/api/net/GT_Packet_TileEntity.java b/src/main/java/gregtech/api/net/GT_Packet_TileEntity.java index 2570a0b4..60343b2f 100644 --- a/src/main/java/gregtech/api/net/GT_Packet_TileEntity.java +++ b/src/main/java/gregtech/api/net/GT_Packet_TileEntity.java @@ -6,6 +6,7 @@ import com.google.common.io.ByteStreams; import gregtech.api.GregTech_API; import gregtech.api.metatileentity.BaseMetaPipeEntity; import gregtech.api.metatileentity.BaseMetaTileEntity; +import io.netty.buffer.ByteBuf; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; @@ -15,13 +16,11 @@ public class GT_Packet_TileEntity extends GT_Packet { private int mX, mZ, mC0, mC1, mC2, mC3, mC4, mC5; private short mY, mID; private byte mTexture, mUpdate, mRedstone, mColor; + private boolean isPipeBaseTile; - public GT_Packet_TileEntity() { - super(true); - } + public GT_Packet_TileEntity() {} - public GT_Packet_TileEntity(int aX, short aY, int aZ, short aID, int aC0, int aC1, int aC2, int aC3, int aC4, int aC5, byte aTexture, byte aUpdate, byte aRedstone, byte aColor) { - super(false); + public GT_Packet_TileEntity(int aX, short aY, int aZ, short aID, int aC0, int aC1, int aC2, int aC3, int aC4, int aC5, byte aTexture, byte aUpdate, byte aRedstone, byte aColor, boolean isPipeBaseTile) { mX = aX; mY = aY; mZ = aZ; @@ -36,12 +35,11 @@ public class GT_Packet_TileEntity extends GT_Packet { mUpdate = aUpdate; mRedstone = aRedstone; mColor = aColor; + this.isPipeBaseTile = isPipeBaseTile; } @Override - public byte[] encode() { - ByteArrayDataOutput tOut = ByteStreams.newDataOutput(40); - + public void encode(ByteBuf tOut) { tOut.writeInt(mX); tOut.writeShort(mY); tOut.writeInt(mZ); @@ -58,24 +56,39 @@ public class GT_Packet_TileEntity extends GT_Packet { tOut.writeByte(mUpdate); tOut.writeByte(mRedstone); tOut.writeByte(mColor); - - return tOut.toByteArray(); + tOut.writeBoolean(isPipeBaseTile); } @Override - public GT_Packet decode(ByteArrayDataInput aData) { - return new GT_Packet_TileEntity(aData.readInt(), aData.readShort(), aData.readInt(), aData.readShort(), aData.readInt(), aData.readInt(), aData.readInt(), aData.readInt(), aData.readInt(), aData.readInt(), aData.readByte(), aData.readByte(), aData.readByte(), aData.readByte()); + public void decode(ByteBuf buf) { + mX = buf.readInt(); + mY = buf.readShort(); + mZ = buf.readInt(); + mID = buf.readShort(); + + mC0 = buf.readInt(); + mC1 = buf.readInt(); + mC2 = buf.readInt(); + mC3 = buf.readInt(); + mC4 = buf.readInt(); + mC5 = buf.readInt(); + + mTexture = buf.readByte(); + mUpdate = buf.readByte(); + mRedstone = buf.readByte(); + mColor = buf.readByte(); + isPipeBaseTile = buf.readBoolean(); } @Override - public void process(IBlockAccess aWorld) { + public void process(World aWorld) { if (aWorld != null) { TileEntity tTileEntity = aWorld.getTileEntity(new BlockPos(mX, mY, mZ)); if(tTileEntity == null) { - tTileEntity = GregTech_API.constructBaseMetaTileEntity(); - tTileEntity.setWorldObj((World) aWorld); + tTileEntity = isPipeBaseTile ? new BaseMetaPipeEntity() : new BaseMetaTileEntity(); + tTileEntity.setWorldObj(aWorld); tTileEntity.setPos(new BlockPos(mX, mY, mZ)); - ((World) aWorld).setTileEntity(new BlockPos(mX, mY, mZ), tTileEntity); + aWorld.setTileEntity(new BlockPos(mX, mY, mZ), tTileEntity); } if (tTileEntity instanceof BaseMetaTileEntity) @@ -85,8 +98,4 @@ public class GT_Packet_TileEntity extends GT_Packet { } } - @Override - public byte getPacketID() { - return 0; - } } \ No newline at end of file diff --git a/src/main/java/gregtech/api/net/IGT_NetworkHandler.java b/src/main/java/gregtech/api/net/IGT_NetworkHandler.java deleted file mode 100644 index 21cfd52a..00000000 --- a/src/main/java/gregtech/api/net/IGT_NetworkHandler.java +++ /dev/null @@ -1,15 +0,0 @@ -package gregtech.api.net; - -import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.world.World; - -public interface IGT_NetworkHandler { - public void sendToPlayer(GT_Packet aPacket, EntityPlayerMP aPlayer); - - public void sendToAllAround(GT_Packet aPacket, TargetPoint aPosition); - - public void sendToServer(GT_Packet aPacket); - - public void sendPacketToAllPlayersInRange(World aWorld, GT_Packet aPacket, int aX, int aZ); -} \ No newline at end of file diff --git a/src/main/java/gregtech/api/objects/GT_CopiedBlockTexture.java b/src/main/java/gregtech/api/objects/GT_CopiedBlockTexture.java index 730dbbd1..85ef0408 100644 --- a/src/main/java/gregtech/api/objects/GT_CopiedBlockTexture.java +++ b/src/main/java/gregtech/api/objects/GT_CopiedBlockTexture.java @@ -1,16 +1,16 @@ package gregtech.api.objects; -import gregtech.api.enums.Dyes; -import gregtech.api.enums.Materials; +import gregtech.api.enums.Textures; import gregtech.api.interfaces.ITexture; +import gregtech.common.render.newblocks.IBlockIconProvider; +import gregtech.common.render.newblocks.RenderUtil; import net.minecraft.block.Block; -import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.renderer.block.model.IBakedModel; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.common.ObfuscationReflectionHelper; +import net.minecraftforge.fml.client.FMLClientHandler; import java.awt.*; import java.util.Collections; @@ -23,44 +23,41 @@ public class GT_CopiedBlockTexture implements ITexture { public int mRGBa; public GT_CopiedBlockTexture(Block aBlock, int aSide, int aMeta, short[] aRGBa) { - if (aRGBa.length != 4) throw new IllegalArgumentException("RGBa doesn't have 4 Values @ GT_CopiedBlockTexture"); mBlock = aBlock; - mRGBa = makeColor(aRGBa); - mSide = (byte) aSide; + mRGBa = aRGBa == null ? -1 : makeColor(aRGBa); + mSide = (byte) (aSide - 1); mMeta = (byte) aMeta; } private int makeColor(short[] rgba) { - short[] nullRGBA = Materials._NULL.getRGBA(); - short red = rgba[0] > 0 && 255 > rgba[0] ? rgba[0] : nullRGBA[0]; - short green = rgba[1] > 0 && 255 > rgba[1] ? rgba[1] : nullRGBA[1]; - short blue = rgba[2] > 0 && 255 > rgba[2] ? rgba[2] : nullRGBA[2]; - short alpha = rgba[3] > 0 && 255 > rgba[3] ? rgba[3] : nullRGBA[3]; - return new Color(red, green, blue, alpha).getRGB(); - } - - public GT_CopiedBlockTexture(Block aBlock, int aSide, int aMeta) { - this(aBlock, aSide, aMeta, Dyes._NULL.mRGBa); - } - - public List getSideQuads(Block aBlock, int aMeta, EnumFacing side) { try { - Minecraft mc = Minecraft.getMinecraft(); - IBlockState blockState = aBlock.getStateFromMeta(aMeta); - IBakedModel model = mc.getBlockRendererDispatcher().getModelForState(blockState); - return model.getQuads(blockState, side, mc.theWorld.rand.nextLong()); - } catch (Throwable error) { - System.out.println("Failed to gen side quads of " + aBlock.getRegistryName() + " " + mMeta); - error.printStackTrace(); - return Collections.emptyList(); + for(int i = 0; i < 4; i++) + rgba[i] = (short) Math.max(0, rgba[i]); + return new Color(rgba[0], rgba[1], rgba[2], rgba[3]).getRGB(); + } catch (IllegalArgumentException err) { + return Color.WHITE.getRGB(); } } + public GT_CopiedBlockTexture(Block aBlock, int aSide, int aMeta) { + this(aBlock, aSide, aMeta, null); + } + + public static TextureAtlasSprite getSide(Block aBlock, int aMeta, EnumFacing side) { + if (aBlock instanceof IBlockIconProvider) { + IBlockIconProvider iconProvider = ((IBlockIconProvider) aBlock); + return iconProvider.getIcon(FMLClientHandler.instance().getWorldClient(), null, side, aMeta); + } + System.out.println("Failed to copy texture of " + aBlock.getRegistryName() + " " + aMeta); + return Textures.BlockIcons.RENDERING_ERROR.getIcon(); + } + @Override - public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOffset) { - List quads = getSideQuads(mBlock, mMeta, EnumFacing.VALUES[mSide > 0 ? mSide - 1 : 0]); - for (BakedQuad bakedQuad : quads) { - ObfuscationReflectionHelper.setPrivateValue(BakedQuad.class, bakedQuad, tintOffset, 1); + public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, float offset) { + TextureAtlasSprite sprite = getSide(mBlock, mMeta, EnumFacing.VALUES[mSide]); + if(sprite != null) { + BakedQuad quad = RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sprite, side, -1, offset, mRGBa, false); + return Collections.singletonList(quad); } return Collections.emptyList(); } diff --git a/src/main/java/gregtech/api/objects/GT_MultiTexture.java b/src/main/java/gregtech/api/objects/GT_MultiTexture.java index d73f7107..b95fa1eb 100644 --- a/src/main/java/gregtech/api/objects/GT_MultiTexture.java +++ b/src/main/java/gregtech/api/objects/GT_MultiTexture.java @@ -16,21 +16,16 @@ import java.util.List; */ public class GT_MultiTexture implements ITexture { private final ITexture[] mTextures; - private final int[] mTexturesTintsMappings; public GT_MultiTexture(ITexture... aTextures) { mTextures = aTextures; - this.mTexturesTintsMappings = new int[aTextures.length]; - for(int i = 0; i < mTextures.length; i++) { - mTexturesTintsMappings[i] = i * 100; - } } @Override - public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOffset) { + public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, float offset) { ArrayList quads = new ArrayList<>(); for(int index = 0; index < mTextures.length; index++) { - quads.addAll(mTextures[index].getQuads(aBlock, blockPos, side, tintOffset + mTexturesTintsMappings[index])); + quads.addAll(mTextures[index].getQuads(aBlock, blockPos, side, offset + 0.001F * index)); } return quads; } diff --git a/src/main/java/gregtech/api/objects/GT_RenderedTexture.java b/src/main/java/gregtech/api/objects/GT_RenderedTexture.java index ac7bfc9a..bcd08f1b 100644 --- a/src/main/java/gregtech/api/objects/GT_RenderedTexture.java +++ b/src/main/java/gregtech/api/objects/GT_RenderedTexture.java @@ -1,10 +1,7 @@ package gregtech.api.objects; -import gregtech.api.enums.Dyes; -import gregtech.api.enums.Materials; import gregtech.api.interfaces.IIconContainer; import gregtech.api.interfaces.ITexture; -import gregtech.api.items.GT_MetaGenerated_Item; import gregtech.api.util.GT_Utility; import gregtech.common.render.newblocks.RenderUtil; import net.minecraft.block.Block; @@ -17,7 +14,6 @@ import net.minecraft.util.math.BlockPos; import java.awt.*; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; public class GT_RenderedTexture implements ITexture { @@ -60,15 +56,15 @@ public class GT_RenderedTexture implements ITexture { } @Override - public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOff) { + public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, float offset) { ArrayList quads = new ArrayList<>(); TextureAtlasSprite sprite = mIconContainer.getIcon(); TextureAtlasSprite overlay = mIconContainer.getOverlayIcon(); if(sprite != null) { - quads.add(RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sprite, side, -1, 0.001F, mRGBa, blockPos == null)); + quads.add(RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sprite, side, -1, offset, mRGBa, false)); } if(overlay != null) { - quads.add(RenderUtil.renderSide(DefaultVertexFormats.BLOCK, overlay, side, -1, 0.001F, mRGBa, blockPos == null)); + quads.add(RenderUtil.renderSide(DefaultVertexFormats.BLOCK, overlay, side, -1, offset + 0.01F, mRGBa, false)); } return quads; } diff --git a/src/main/java/gregtech/api/objects/GT_SidedTexture.java b/src/main/java/gregtech/api/objects/GT_SidedTexture.java index 3360bd69..cade3b91 100644 --- a/src/main/java/gregtech/api/objects/GT_SidedTexture.java +++ b/src/main/java/gregtech/api/objects/GT_SidedTexture.java @@ -24,12 +24,13 @@ public class GT_SidedTexture implements ITexture { } private int makeColor(short[] rgba) { - short[] nullRGBA = Materials._NULL.getRGBA(); - short red = rgba[0] > 0 && 255 > rgba[0] ? rgba[0] : nullRGBA[0]; - short green = rgba[1] > 0 && 255 > rgba[1] ? rgba[1] : nullRGBA[1]; - short blue = rgba[2] > 0 && 255 > rgba[2] ? rgba[2] : nullRGBA[2]; - short alpha = rgba[3] > 0 && 255 > rgba[3] ? rgba[3] : nullRGBA[3]; - return new Color(red, green, blue, alpha).getRGB(); + try { + for(int i = 0; i < 4; i++) + rgba[i] = (short) Math.max(0, rgba[i]); + return new Color(rgba[0], rgba[1], rgba[2], rgba[3]).getRGB(); + } catch (IllegalArgumentException err) { + return Color.WHITE.getRGB(); + } } public GT_SidedTexture(IIconContainer aIcon0, IIconContainer aIcon1, IIconContainer aIcon2, IIconContainer aIcon3, IIconContainer aIcon4, IIconContainer aIcon5) { @@ -45,9 +46,9 @@ public class GT_SidedTexture implements ITexture { } @Override - public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOffset) { + public List getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, float offset) { return new GT_RenderedTexture(mIconContainer[side.getIndex()], mRGBa) - .getQuads(aBlock, blockPos, side, tintOffset); + .getQuads(aBlock, blockPos, side, offset); } @Override diff --git a/src/main/java/gregtech/api/util/GT_Utility.java b/src/main/java/gregtech/api/util/GT_Utility.java index 2eccfa2d..40921797 100644 --- a/src/main/java/gregtech/api/util/GT_Utility.java +++ b/src/main/java/gregtech/api/util/GT_Utility.java @@ -38,6 +38,7 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.init.MobEffects; import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; @@ -951,7 +952,7 @@ public class GT_Utility { public static boolean sendSoundToPlayers(World aWorld, String aSoundName, float aSoundStrength, float aSoundModulation, int aX, int aY, int aZ) { if (isStringInvalid(aSoundName) || aWorld == null || aWorld.isRemote) return false; - NW.sendPacketToAllPlayersInRange(aWorld, new GT_Packet_Sound(aSoundName, aSoundStrength, aSoundModulation, aX, (short) aY, aZ), aX, aZ); + NW.sendToAllAround(aWorld, new GT_Packet_Sound(aSoundName, aSoundStrength, aSoundModulation, aX, (short) aY, aZ), aX, aY, aZ); return true; } public static boolean sendSoundToPlayers(World aWorld, String aSoundName, float aSoundStrength, float aSoundModulation, BlockPos blockPos) { @@ -1242,7 +1243,7 @@ public class GT_Utility { } public static boolean applyHeatDamage(EntityLivingBase aEntity, float aDamage) { - if (aDamage > 0 && aEntity != null && aEntity.getActivePotionEffect(Potion.getPotionFromResourceLocation("fire_resistance")) == null && !isWearingFullHeatHazmat(aEntity)) { + if (aDamage > 0 && aEntity != null && aEntity.getActivePotionEffect(MobEffects.FIRE_RESISTANCE) == null && !isWearingFullHeatHazmat(aEntity)) { aEntity.attackEntityFrom(GT_DamageSources.getHeatDamage(), aDamage); return true; } @@ -1268,10 +1269,10 @@ public class GT_Utility { public static boolean applyRadioactivity(EntityLivingBase aEntity, int aLevel, int aAmountOfItems) { if (aLevel > 0 && aEntity != null && aEntity.getCreatureAttribute() != EnumCreatureAttribute.UNDEAD && aEntity.getCreatureAttribute() != EnumCreatureAttribute.ARTHROPOD && !isWearingFullRadioHazmat(aEntity)) { - aEntity.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("slowness"), aLevel * 140 * aAmountOfItems)); - aEntity.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("confusion"), aLevel * 130 * aAmountOfItems)); - aEntity.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("weakness"), aLevel * 150 * aAmountOfItems)); - aEntity.addPotionEffect(new PotionEffect(Potion.getPotionFromResourceLocation("hunger"), aLevel * 130 * aAmountOfItems)); + aEntity.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, aLevel * 140 * aAmountOfItems)); + aEntity.addPotionEffect(new PotionEffect(MobEffects.NAUSEA, aLevel * 130 * aAmountOfItems)); + aEntity.addPotionEffect(new PotionEffect(MobEffects.WEAKNESS, aLevel * 150 * aAmountOfItems)); + aEntity.addPotionEffect(new PotionEffect(MobEffects.HUNGER, aLevel * 130 * aAmountOfItems)); aEntity.addPotionEffect(new PotionEffect(IC2Potion.radiation, aLevel * 180 * aAmountOfItems)); return true; } diff --git a/src/main/java/gregtech/common/GT_Network.java b/src/main/java/gregtech/common/GT_Network.java deleted file mode 100644 index 26f54389..00000000 --- a/src/main/java/gregtech/common/GT_Network.java +++ /dev/null @@ -1,98 +0,0 @@ -package gregtech.common; - -import com.google.common.io.ByteArrayDataInput; -import com.google.common.io.ByteStreams; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.common.network.FMLEmbeddedChannel; -import net.minecraftforge.fml.common.network.FMLOutboundHandler; -import net.minecraftforge.fml.common.network.NetworkRegistry; -import net.minecraftforge.fml.common.network.internal.FMLProxyPacket; -import net.minecraftforge.fml.relauncher.Side; -import gregtech.api.enums.GT_Values; -import gregtech.api.net.*; -import gregtech.common.blocks.GT_Packet_Ores; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.MessageToMessageCodec; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.world.World; -import net.minecraft.world.chunk.Chunk; - -import java.util.EnumMap; -import java.util.List; - -@ChannelHandler.Sharable -public class GT_Network - extends MessageToMessageCodec - implements IGT_NetworkHandler { - - private final EnumMap mChannel; - private final GT_Packet[] mSubChannels; - - public GT_Network() { - this.mChannel = NetworkRegistry.INSTANCE.newChannel("GregTech", this, new HandlerShared()); - this.mSubChannels = new GT_Packet[]{new GT_Packet_TileEntity(), new GT_Packet_Sound(), new GT_Packet_Block_Event(), new GT_Packet_Ores()}; - } - - @Override - protected void encode(ChannelHandlerContext aContext, GT_Packet aPacket, List aOutput) throws Exception { - PacketBuffer packetBuffer = new PacketBuffer(Unpooled.buffer()); - packetBuffer.writeByte(aPacket.getPacketID()); - packetBuffer.writeBytes(aPacket.encode()); - aOutput.add(new FMLProxyPacket(packetBuffer, aContext - .channel().attr(NetworkRegistry.FML_CHANNEL).get())); - } - - @Override - protected void decode(ChannelHandlerContext aContext, FMLProxyPacket aPacket, List aOutput) - throws Exception { - ByteArrayDataInput aData = ByteStreams.newDataInput(aPacket.payload().array()); - aOutput.add(this.mSubChannels[aData.readByte()].decode(aData)); - } - - public void sendToPlayer(GT_Packet aPacket, EntityPlayerMP aPlayer) { - this.mChannel.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.PLAYER); - this.mChannel.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(aPlayer); - this.mChannel.get(Side.SERVER).writeAndFlush(aPacket); - } - - public void sendToAllAround(GT_Packet aPacket, NetworkRegistry.TargetPoint aPosition) { - this.mChannel.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.ALLAROUNDPOINT); - this.mChannel.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(aPosition); - this.mChannel.get(Side.SERVER).writeAndFlush(aPacket); - } - - public void sendToServer(GT_Packet aPacket) { - this.mChannel.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.TOSERVER); - this.mChannel.get(Side.CLIENT).writeAndFlush(aPacket); - } - - public void sendPacketToAllPlayersInRange(World aWorld, GT_Packet aPacket, int aX, int aZ) { - if (!aWorld.isRemote) { - for (Object tObject : aWorld.playerEntities) { - if (!(tObject instanceof EntityPlayerMP)) { - break; - } - EntityPlayerMP tPlayer = (EntityPlayerMP) tObject; - Chunk tChunk = aWorld.getChunkFromBlockCoords(new BlockPos(aX, 0, aZ)); - if (tPlayer.getServerWorld().getPlayerChunkMap().isPlayerWatchingChunk(tPlayer, tChunk.xPosition, tChunk.zPosition)) { - sendToPlayer(aPacket, tPlayer); - } - } - } - } - - @ChannelHandler.Sharable - static final class HandlerShared - extends SimpleChannelInboundHandler { - protected void channelRead0(ChannelHandlerContext ctx, GT_Packet aPacket) - throws Exception { - EntityPlayer aPlayer = GT_Values.GT.getThePlayer(); - aPacket.process(aPlayer == null ? null : GT_Values.GT.getThePlayer().worldObj); - } - } -} diff --git a/src/main/java/gregtech/common/GT_Worldgenerator.java b/src/main/java/gregtech/common/GT_Worldgenerator.java index 03388b45..711ac9d3 100644 --- a/src/main/java/gregtech/common/GT_Worldgenerator.java +++ b/src/main/java/gregtech/common/GT_Worldgenerator.java @@ -30,8 +30,8 @@ public class GT_Worldgenerator implements IWorldGenerator { private static int endMinSize = 50; private static int endMaxSize = 200; private static boolean endAsteroids = true; - public List mList = new CopyOnWriteArrayList<>(); - public boolean mIsGenerating = false; + //public List mList = new CopyOnWriteArrayList<>(); + //public boolean mIsGenerating = false; public GT_Worldgenerator() { @@ -44,14 +44,11 @@ public class GT_Worldgenerator implements IWorldGenerator { @Override public void generate(Random aRandom, int aX, int aZ, World aWorld, IChunkGenerator aChunkGenerator, IChunkProvider aChunkProvider) { - if(aRandom.nextInt(4) == 0) { - //TODO less lag on ore gen - Biome biome = aWorld.getBiomeGenForCoords(new BlockPos(aX * 16 + 8, 16, aZ * 16 + 8)); - new WorldGenContainer(new Random(aRandom.nextInt()), aX * 16, aZ * 16, - (aChunkGenerator instanceof ChunkProviderEnd || biome == Biomes.SKY) ? 1 : - (aChunkGenerator instanceof ChunkProviderHell || biome == Biomes.HELL) ? -1 : 0, - aWorld, aChunkGenerator, aChunkProvider, biome.getBiomeName()).run(); - } + Biome biome = aWorld.getBiomeGenForCoords(new BlockPos(aX * 16 + 8, 16, aZ * 16 + 8)); + new WorldGenContainer(new Random(aRandom.nextInt()), aX * 16, aZ * 16, + (aChunkGenerator instanceof ChunkProviderEnd || biome == Biomes.SKY) ? 1 : + (aChunkGenerator instanceof ChunkProviderHell || biome == Biomes.HELL) ? -1 : 0, + aWorld, aChunkGenerator, aChunkProvider, biome.getBiomeName()).run(); } public static class WorldGenContainer diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Casings1.java b/src/main/java/gregtech/common/blocks/GT_Block_Casings1.java index 19cd1a6f..1fa7332b 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Casings1.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Casings1.java @@ -6,6 +6,7 @@ import gregtech.api.enums.Textures; import gregtech.api.objects.GT_CopiedBlockTexture; import gregtech.api.util.GT_LanguageManager; import net.minecraft.block.state.IBlockState; +import net.minecraft.client.renderer.color.IBlockColor; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; @@ -14,7 +15,7 @@ import net.minecraft.world.IBlockAccess; import javax.annotation.Nullable; -public class GT_Block_Casings1 extends GT_Block_Casings_Abstract { +public class GT_Block_Casings1 extends GT_Block_Casings_Abstract implements IBlockColor { public GT_Block_Casings1() { super(GT_Item_Casings1.class, "gt.blockcasings", GT_Material_Casings.INSTANCE); for (byte i = 0; i < 16; i = (byte) (i + 1)) { diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Casings4.java b/src/main/java/gregtech/common/blocks/GT_Block_Casings4.java index 66a04b09..b452ab74 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Casings4.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Casings4.java @@ -30,8 +30,8 @@ public class GT_Block_Casings4 extends GT_Block_Casings_Abstract { GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".1.name", "Clean Stainless Steel Casing"); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".2.name", "Stable Titanium Casing"); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".3.name", "Titanium Firebox Casing"); -// GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".4.name", "Fusion Casing"); -// GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".5.name", "Fusion Casing"); + GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".4.name", "Fusion Casing"); + GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".5.name", "Fusion Casing"); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".6.name", "Fusion Casing"); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".7.name", "Fusion Coil"); GT_LanguageManager.addStringLocalization(getUnlocalizedName() + ".8.name", "Fusion Casing MK II"); diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Casings_Abstract.java b/src/main/java/gregtech/common/blocks/GT_Block_Casings_Abstract.java index 62c34bbc..2f156087 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Casings_Abstract.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Casings_Abstract.java @@ -31,7 +31,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import javax.annotation.Nullable; import java.util.List; -public abstract class GT_Block_Casings_Abstract extends GT_Generic_Block implements IBlockIconProvider, IBlockColor { +public abstract class GT_Block_Casings_Abstract extends GT_Generic_Block implements IBlockIconProvider { public GT_Block_Casings_Abstract(Class aItemClass, String aName, Material aMaterial) { @@ -100,16 +100,6 @@ public abstract class GT_Block_Casings_Abstract extends GT_Generic_Block impleme return GT_LanguageManager.getTranslation(this.mUnlocalizedName + ".name"); } - @Override - public boolean canBeReplacedByLeaves(IBlockState state, IBlockAccess world, BlockPos pos) { - return false; - } - - @Override - public boolean isOpaqueCube(IBlockState state) { - return true; - } - @Override public boolean canCreatureSpawn(IBlockState state, IBlockAccess world, BlockPos pos, EntityLiving.SpawnPlacementType type) { return false; @@ -128,9 +118,4 @@ public abstract class GT_Block_Casings_Abstract extends GT_Generic_Block impleme } } - @Override - public int colorMultiplier(IBlockState state, @Nullable IBlockAccess worldIn, @Nullable BlockPos pos, int tintIndex) { - return Dyes._NULL.getRGBAInt(); - } - } diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Concretes.java b/src/main/java/gregtech/common/blocks/GT_Block_Concretes.java index b148c568..27d38ebc 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Concretes.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Concretes.java @@ -69,8 +69,7 @@ public class GT_Block_Concretes extends GT_Block_Stones_Abstract { @Override public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity aEntity) { - Block tBlock = worldIn.getBlockState(pos.up()).getBlock(); - if (((aEntity instanceof EntityLivingBase)) && (!(tBlock instanceof IFluidBlock)) && (!(tBlock instanceof BlockLiquid)) && (aEntity.onGround) && (!aEntity.isInWater()) && (!aEntity.isWet())) { + if (aEntity.onGround && !aEntity.isInWater()) { if (aEntity.isSneaking()) { aEntity.motionX *= 0.8999999761581421D; aEntity.motionZ *= 0.8999999761581421D; @@ -87,10 +86,10 @@ public class GT_Block_Concretes extends GT_Block_Stones_Abstract { @Override public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, World aWorld, BlockPos pos) { Block tBlock = aWorld.getBlockState(pos.up()).getBlock(); - if (((tBlock instanceof IFluidBlock)) || ((tBlock instanceof BlockLiquid))) { - return super.getCollisionBoundingBox(blockState, aWorld, pos); + if (tBlock instanceof IFluidBlock || tBlock instanceof BlockLiquid) { + return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); } - return new AxisAlignedBB(pos, pos.add(1, 0.875D, 1)); + return new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.875D, 1.0D); } } 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 1adaaff3..33d54a7b 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Machines.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Machines.java @@ -30,6 +30,7 @@ import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumDyeColor; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -307,7 +308,7 @@ public class GT_Block_Machines extends GT_Generic_Block implements IDebugableBlo gregTechTileEntity.onRightclick(playerIn, (byte) side.getIndex(), hitX, hitY, hitZ, hand); return true; } - return false; + return true; } @Override @@ -519,7 +520,9 @@ public class GT_Block_Machines extends GT_Generic_Block implements IDebugableBlo return null; } - public boolean recolourBlock(World aWorld, BlockPos blockPos, EnumFacing aSide, int aColor) { + @Override + public boolean recolorBlock(World aWorld, BlockPos blockPos, EnumFacing aSide, EnumDyeColor colorDye) { + int aColor = colorDye.getMetadata(); TileEntity tTileEntity = aWorld.getTileEntity(blockPos); if ((tTileEntity instanceof IGregTechTileEntity)) { if (((IGregTechTileEntity) tTileEntity).getColorization() == (byte) ((~aColor) & 0xF)) { @@ -531,11 +534,4 @@ public class GT_Block_Machines extends GT_Generic_Block implements IDebugableBlo return false; } - @Override - @SideOnly(Side.CLIENT) - public BlockRenderLayer getBlockLayer() { - return BlockRenderLayer.CUTOUT; - } - - } diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java b/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java index e14c2f3d..3cdba3a4 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Ores_Abstract.java @@ -107,14 +107,6 @@ public abstract class GT_Block_Ores_Abstract extends GT_Generic_Block implements } - @Override - public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn) { - GT_TileEntity_Ores tileEntity_ores = (GT_TileEntity_Ores) worldIn.getTileEntity(pos); - if (tileEntity_ores != null && !worldIn.isRemote) { - tileEntity_ores.sendPacket(); - } - } - public String getLocalizedName(Materials aMaterial) { switch (aMaterial) { case InfusedAir: @@ -285,8 +277,4 @@ public abstract class GT_Block_Ores_Abstract extends GT_Generic_Block implements } } - @Override - public BlockRenderLayer getBlockLayer() { - return BlockRenderLayer.CUTOUT; - } } diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Reinforced.java b/src/main/java/gregtech/common/blocks/GT_Block_Reinforced.java index 27490fe8..65cbe657 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Reinforced.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Reinforced.java @@ -168,21 +168,6 @@ public class GT_Block_Reinforced extends GT_Generic_Block implements IBlockIconP return GT_LanguageManager.getTranslation(this.mUnlocalizedName + ".name"); } - @Override - public boolean isBlockNormalCube(IBlockState state) { - return true; - } - - @Override - public boolean isVisuallyOpaque() { - return true; - } - - @Override - public boolean canCreatureSpawn(IBlockState state, IBlockAccess world, BlockPos pos, EntityLiving.SpawnPlacementType type) { - return super.canCreatureSpawn(state, world, pos, type); - } - @Override public List getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune) { return Lists.newArrayList(new ItemStack(this, 1, state.getValue(METADATA))); @@ -197,73 +182,6 @@ public class GT_Block_Reinforced extends GT_Generic_Block implements IBlockIconP } } - @Override - public boolean removedByPlayer(IBlockState state, World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { - if(state.getValue(METADATA) == 5) { - EntityIC2Explosive entitytntprimed = getExplosionEntity(world, pos.getX(), pos.getY(), pos.getZ(), player == null ? null : player); - world.spawnEntityInWorld(entitytntprimed); - world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F, false); - } - return true; - } - - public EntityIC2Explosive getExplosionEntity(World world, int x, int y, int z, EntityLivingBase igniter) { - EntityIC2Explosive ret = new EntityItnt(world, x + 0.5D, y + 0.5D, z + 0.5D); - ret.setIgniter(igniter); - return ret; - } - - public void checkAndExplode(World world, BlockPos pos) { - if(world.isBlockIndirectlyGettingPowered(pos) > 0) { - explode(world, pos); - } - } - - public void explode(World world, BlockPos pos) { - EntityIC2Explosive entitytntprimed = getExplosionEntity(world, pos.getX(), pos.getY(), pos.getZ(), null); - world.spawnEntityInWorld(entitytntprimed); - world.playSound(pos.getX(), pos.getY(), pos.getZ(), SoundEvents.ENTITY_TNT_PRIMED, SoundCategory.BLOCKS, 1.0F, 1.0F, false); - world.setBlockToAir(pos); - } - - @Override - public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) { - super.onBlockAdded(worldIn, pos, state); - if(state.getValue(METADATA) == 5) { - checkAndExplode(worldIn, pos); - } - } - - @Override - public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) { - super.onNeighborChange(world, pos, neighbor); - if(world.getBlockState(pos).getValue(METADATA) == 5) { - checkAndExplode((World) world, pos); - } - } - - @Override - public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn) { - super.onBlockDestroyedByExplosion(worldIn, pos, explosionIn); - if(worldIn.getBlockState(pos).getValue(METADATA) == 5) { - checkAndExplode(worldIn, pos); - } - } - - - @Override - public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { - if(state.getValue(METADATA) == 5) { - ItemStack held = playerIn.getHeldItem(hand); - if (held != null && held.getItem() == Items.FLINT_AND_STEEL) { - held.damageItem(1, playerIn); - explode(worldIn, pos); - return true; - } - } - return false; - } - @SideOnly(Side.CLIENT) public void getSubBlocks(Item aItem, CreativeTabs par2CreativeTabs, List aList) { for (int i = 0; i < 16; i++) { diff --git a/src/main/java/gregtech/common/blocks/GT_Block_Stones_Abstract.java b/src/main/java/gregtech/common/blocks/GT_Block_Stones_Abstract.java index 7eae3fe6..44281249 100644 --- a/src/main/java/gregtech/common/blocks/GT_Block_Stones_Abstract.java +++ b/src/main/java/gregtech/common/blocks/GT_Block_Stones_Abstract.java @@ -109,16 +109,6 @@ public abstract class GT_Block_Stones_Abstract extends GT_Generic_Block implemen return null; } - @Override - public boolean canBeReplacedByLeaves(IBlockState state, IBlockAccess world, BlockPos pos) { - return false; - } - - @Override - public boolean isOpaqueCube(IBlockState state) { - return true; - } - @Override public boolean canCreatureSpawn(IBlockState state, IBlockAccess world, BlockPos pos, EntityLiving.SpawnPlacementType type) { return state.getValue(METADATA) % 8 < 3; diff --git a/src/main/java/gregtech/common/blocks/GT_Packet_Ores.java b/src/main/java/gregtech/common/blocks/GT_Packet_Ores.java index 4589c650..63872103 100644 --- a/src/main/java/gregtech/common/blocks/GT_Packet_Ores.java +++ b/src/main/java/gregtech/common/blocks/GT_Packet_Ores.java @@ -5,63 +5,101 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine; import gregtech.api.net.GT_Packet; +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; +import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -public class GT_Packet_Ores - extends GT_Packet { - private int mX; - private int mZ; - private int mY; - private short mMetaData; +import java.util.ArrayList; - public GT_Packet_Ores() { - super(true); - } +public class GT_Packet_Ores extends GT_Packet { - public GT_Packet_Ores(BlockPos blockPos, short aMetaData) { - super(false); - this.mX = blockPos.getX(); - this.mY = blockPos.getY(); - this.mZ = blockPos.getZ(); - this.mMetaData = aMetaData; - } + private ArrayList ores = new ArrayList<>(); - @Override - public byte[] encode() { - ByteArrayDataOutput tOut = ByteStreams.newDataOutput(12); + private static class OreInfo { + private int mX; + private int mZ; + private int mY; + private short mMetaData; - tOut.writeInt(this.mX); - tOut.writeShort(this.mY); - tOut.writeInt(this.mZ); - tOut.writeShort(this.mMetaData); + public OreInfo(BlockPos pos, short metadata) { + mX = pos.getX(); + mY = pos.getY(); + mZ = pos.getZ(); + mMetaData = metadata; + } - return tOut.toByteArray(); - } + private OreInfo() {} - @Override - public GT_Packet decode(ByteArrayDataInput aData) { - return new GT_Packet_Ores(new BlockPos(aData.readInt(), aData.readShort(), aData.readInt()), aData.readShort()); - } + public void encode(ByteBuf tOut) { + tOut.writeInt(this.mX); + tOut.writeShort(this.mY); + tOut.writeInt(this.mZ); + tOut.writeShort(this.mMetaData); + } - @Override - public void process(IBlockAccess aWorld) { - if (aWorld != null) { - BlockPos blockPos = new BlockPos(this.mX, this.mY, this.mZ); - GT_TileEntity_Ores tileEntity_ores = (GT_TileEntity_Ores) aWorld.getTileEntity(blockPos); - if(tileEntity_ores != null) { - tileEntity_ores.mMetaData = mMetaData; - tileEntity_ores.causeChunkUpdate(); + public void decode(ByteBuf buf) { + mX = buf.readInt(); + mY = buf.readShort(); + mZ = buf.readInt(); + mMetaData = buf.readShort(); + } + + public static OreInfo decodeNew(ByteBuf buf) { + OreInfo oreInfo = new OreInfo(); + oreInfo.decode(buf); + return oreInfo; + } + + public void process(World aWorld) { + if (aWorld != null && mMetaData > 0) { + BlockPos blockPos = new BlockPos(this.mX, this.mY, this.mZ); + GT_TileEntity_Ores tileEntity_ores = (GT_TileEntity_Ores) aWorld.getTileEntity(blockPos); + if(tileEntity_ores != null) { + tileEntity_ores.mMetaData = mMetaData; + tileEntity_ores.causeChunkUpdate(); + } } } + + + } + + public GT_Packet_Ores() {} + + public void addPos(GT_TileEntity_Ores tileEntity_ores) { + ores.add(new OreInfo(tileEntity_ores.getPos(), tileEntity_ores.mMetaData)); + } + + public boolean isEmpty() { + return ores.isEmpty(); + } + + @Override + public void encode(ByteBuf buf) { + buf.writeInt(ores.size()); + for(int i = 0; i < ores.size(); i++) { + ores.get(i).encode(buf); + } } @Override - public byte getPacketID() { - return 3; + public void decode(ByteBuf buf) { + int size = buf.readInt(); + for(int i = 0; i < size; i++) { + ores.add(OreInfo.decodeNew(buf)); + } } + + @Override + public void process(World aWorld) { + for(OreInfo oreInfo : ores) { + oreInfo.process(aWorld); + } + } + } diff --git a/src/main/java/gregtech/common/blocks/GT_TickHandler_Ores.java b/src/main/java/gregtech/common/blocks/GT_TickHandler_Ores.java index 8cf07e7d..3afe2e69 100644 --- a/src/main/java/gregtech/common/blocks/GT_TickHandler_Ores.java +++ b/src/main/java/gregtech/common/blocks/GT_TickHandler_Ores.java @@ -1,6 +1,8 @@ package gregtech.common.blocks; +import gregtech.api.enums.GT_Values; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -49,19 +51,25 @@ public class GT_TickHandler_Ores { @SubscribeEvent public void onPlayerTick(TickEvent.PlayerTickEvent player) { - EntityPlayer entityPlayer = player.player; - World world = entityPlayer.worldObj; - if(world.getWorldTime() % 40 == 0) { - ChunkCoordIntPair chunk = new ChunkCoordIntPair(new BlockPos(entityPlayer)); - for (int x = -1; x < 1; x++) { - for (int z = -1; z < 1; z++) { - ChunkCoordIntPair offset = chunk.offset(x, z); - ArrayList ores = getChunkData(world.provider.getDimension(), offset); - ores.removeIf(TileEntity::isInvalid); - for(GT_TileEntity_Ores oresTile : ores) { - if(!oresTile.isBlocked()) oresTile.sendPacket(); + if(player.side.isServer()) { + EntityPlayer entityPlayer = player.player; + World world = entityPlayer.worldObj; + if (world.getWorldTime() % 10 == 0) { + GT_Packet_Ores packet_ores = new GT_Packet_Ores(); + ChunkCoordIntPair chunk = new ChunkCoordIntPair(new BlockPos(entityPlayer)); + for (int x = -1; x < 1; x++) { + for (int z = -1; z < 1; z++) { + ChunkCoordIntPair offset = chunk.offset(x, z); + ArrayList ores = getChunkData(world.provider.getDimension(), offset); + ores.removeIf(TileEntity::isInvalid); + for (GT_TileEntity_Ores oresTile : ores) { + packet_ores.addPos(oresTile); + } } } + if (!packet_ores.isEmpty()) { + GT_Values.NW.sendTo(packet_ores, (EntityPlayerMP) entityPlayer); + } } } } diff --git a/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java b/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java index b2edc6bd..f143a2b2 100644 --- a/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java +++ b/src/main/java/gregtech/common/blocks/GT_TileEntity_Ores.java @@ -115,14 +115,6 @@ public class GT_TileEntity_Ores extends TileEntity implements ITexturedTileEntit return aNBT; } - public void sendPacket() { - if (!worldObj.isRemote) { - GT_Values.NW.sendPacketToAllPlayersInRange(this.worldObj, - new GT_Packet_Ores(getPos(), this.mMetaData), - getPos().getX(), getPos().getZ()); - } - } - @SideOnly(Side.CLIENT) public void causeChunkUpdate() { int minX = pos.getX() - 5; diff --git a/src/main/java/gregtech/common/render/newblocks/BlockRenderer.java b/src/main/java/gregtech/common/render/newblocks/BlockRenderer.java index c755a09b..dd073b19 100644 --- a/src/main/java/gregtech/common/render/newblocks/BlockRenderer.java +++ b/src/main/java/gregtech/common/render/newblocks/BlockRenderer.java @@ -78,7 +78,7 @@ public class BlockRenderer { if(side != null) { TextureAtlasSprite sideIcon = getSideSprite(side); if (sideIcon != null) { - BakedQuad faceQuad = RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sideIcon, side, side.getIndex(), 0.0F, -1, true); + BakedQuad faceQuad = RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sideIcon, side, -1, 0.0F, -1, false); if (faceQuad != null) { return Collections.singletonList(faceQuad); } @@ -101,7 +101,7 @@ public class BlockRenderer { if(side != null && state != null) { TextureAtlasSprite sideIcon = getSideSprite(side, state); if (sideIcon != null) { - BakedQuad faceQuad = RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sideIcon, side, side.getIndex(), 0.0F, -1, false); + BakedQuad faceQuad = RenderUtil.renderSide(DefaultVertexFormats.BLOCK, sideIcon, side, -1, 0.0F, -1, false); if (faceQuad != null) { return Collections.singletonList(faceQuad); } @@ -128,9 +128,9 @@ public class BlockRenderer { BlockPos pos = blockState.getValue(GT_Generic_Block.BLOCK_POS); ITextureBlockIconProvider provider = (ITextureBlockIconProvider) blockState.getBlock(); ITexture[] textures = provider.getTexture(Minecraft.getMinecraft().theWorld, pos, blockState, side); - for (ITexture texture : textures) { - if(texture != null) { - quads.addAll(texture.getQuads(state.getBlock(), pos, side, side.getIndex())); + for (int i = 0; i < textures.length; i++) { + if(textures[i] != null) { + quads.addAll(textures[i].getQuads(state.getBlock(), pos, side, i * 0.01F)); } } return quads; @@ -155,14 +155,12 @@ public class BlockRenderer { @Override public List getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) { if(side != null) { - GlStateManager.enableLighting(); - RenderHelper.enableGUIStandardItemLighting(); ArrayList quads = new ArrayList<>(); ITextureBlockIconProvider provider = (ITextureBlockIconProvider) block; ITexture[] textures = provider.getItemblockTexture(holder, itemStack, side); - for (ITexture texture : textures) { - if(texture != null) { - quads.addAll(texture.getQuads(block, null, side, side.getIndex())); + for (int i = 0; i < textures.length; i++) { + if(textures[i] != null) { + quads.addAll(textures[i].getQuads(block, null, side, i * 0.01F)); } } return quads; diff --git a/src/main/java/gregtech/common/render/newblocks/IBlockIconProvider.java b/src/main/java/gregtech/common/render/newblocks/IBlockIconProvider.java index dc7318e3..87d87ed6 100644 --- a/src/main/java/gregtech/common/render/newblocks/IBlockIconProvider.java +++ b/src/main/java/gregtech/common/render/newblocks/IBlockIconProvider.java @@ -1,6 +1,5 @@ package gregtech.common.render.newblocks; -import gregtech.api.items.GT_Generic_Block; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; diff --git a/src/main/java/gregtech/common/render/newblocks/RenderUtil.java b/src/main/java/gregtech/common/render/newblocks/RenderUtil.java index a078ed4e..87184ebb 100644 --- a/src/main/java/gregtech/common/render/newblocks/RenderUtil.java +++ b/src/main/java/gregtech/common/render/newblocks/RenderUtil.java @@ -6,30 +6,24 @@ import net.minecraft.client.renderer.vertex.VertexFormat; import net.minecraft.util.EnumFacing; import net.minecraftforge.client.model.pipeline.UnpackedBakedQuad; -import javax.vecmath.Vector3d; -import javax.vecmath.Vector3f; -import java.awt.*; - public class RenderUtil { public static BakedQuad renderSide(VertexFormat vertexFormat, TextureAtlasSprite sprite, EnumFacing side, int tint, float offset, int color, boolean hideSiding) { switch (side) { case NORTH: - //front return buildQuad(vertexFormat, hideSiding ? null : EnumFacing.NORTH, sprite, tint, - 0, 0, -offset, sprite.getMinU(), sprite.getMinV(), - 0, 1, -offset, sprite.getMinU(), sprite.getMaxV(), - 1, 1, -offset, sprite.getMaxU(), sprite.getMaxV(), - 1, 0, -offset, sprite.getMaxU(), sprite.getMinV(), + 0, 0, -offset, sprite.getMaxU(), sprite.getMaxV(), + 0, 1, -offset, sprite.getMaxU(), sprite.getMinV(), + 1, 1, -offset, sprite.getMinU(), sprite.getMinV(), + 1, 0, -offset, sprite.getMinU(), sprite.getMaxV(), color); case SOUTH: - // back return buildQuad(vertexFormat, hideSiding ? null : EnumFacing.SOUTH, sprite, tint, - 1, 0, 1 + offset, sprite.getMaxU(), sprite.getMinV(), - 1, 1, 1 + offset, sprite.getMaxU(), sprite.getMaxV(), - 0, 1, 1 + offset, sprite.getMinU(), sprite.getMaxV(), - 0, 0, 1 + offset, sprite.getMinU(), sprite.getMinV(), + 1, 0, 1 + offset, sprite.getMinU(), sprite.getMaxV(), + 1, 1, 1 + offset, sprite.getMinU(), sprite.getMinV(), + 0, 1, 1 + offset, sprite.getMaxU(), sprite.getMinV(), + 0, 0, 1 + offset, sprite.getMaxU(), sprite.getMaxV(), color); case WEST: return buildQuad(vertexFormat, hideSiding ? null : EnumFacing.WEST, sprite, tint,