Lightning fix, black blocks on break attempt fix
This commit is contained in:
parent
7f1791abbf
commit
d490759e8d
37 changed files with 351 additions and 708 deletions
|
@ -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()) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ import java.util.List;
|
|||
|
||||
public interface ITexture {
|
||||
|
||||
public List<BakedQuad> getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOffset);
|
||||
public List<BakedQuad> getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, float offset);
|
||||
|
||||
public boolean isValidTexture();
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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,
|
||||
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), getXCoord(), getZCoord());
|
||||
mSendClientData = false;
|
||||
}
|
||||
}
|
||||
| ((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:
|
||||
|
|
|
@ -278,9 +278,8 @@ 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(
|
||||
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],
|
||||
|
@ -289,9 +288,8 @@ public class BaseMetaTileEntity extends BaseTileEntity implements IGregTechTileE
|
|||
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());
|
||||
}
|
||||
((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);
|
||||
|
|
|
@ -1,98 +0,0 @@
|
|||
package gregtech.api.metatileentity;
|
||||
|
||||
|
||||
/**
|
||||
* NEVER INCLUDE THIS FILE IN YOUR MOD!!!
|
||||
* <p/>
|
||||
* This file contains all the needed 'implements' of the Interfaces for the Universal Electricity Stuff.
|
||||
* <p/>
|
||||
* 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<ForgeDirection> getUEConsumingSides() {
|
||||
EnumSet<ForgeDirection> 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<ForgeDirection> getUEProducingSides() {
|
||||
EnumSet<ForgeDirection> 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;
|
||||
}*/
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
46
src/main/java/gregtech/api/net/GT_PacketHandler.java
Normal file
46
src/main/java/gregtech/api/net/GT_PacketHandler.java
Normal file
|
@ -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<GT_Packet, GT_Packet> {
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
|
@ -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();
|
||||
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_CopiedBlockTexture(Block aBlock, int aSide, int aMeta) {
|
||||
this(aBlock, aSide, aMeta, Dyes._NULL.mRGBa);
|
||||
this(aBlock, aSide, aMeta, null);
|
||||
}
|
||||
|
||||
public List<BakedQuad> 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();
|
||||
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<BakedQuad> getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOffset) {
|
||||
List<BakedQuad> quads = getSideQuads(mBlock, mMeta, EnumFacing.VALUES[mSide > 0 ? mSide - 1 : 0]);
|
||||
for (BakedQuad bakedQuad : quads) {
|
||||
ObfuscationReflectionHelper.setPrivateValue(BakedQuad.class, bakedQuad, tintOffset, 1);
|
||||
public List<BakedQuad> 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();
|
||||
}
|
||||
|
|
|
@ -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<BakedQuad> getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOffset) {
|
||||
public List<BakedQuad> getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, float offset) {
|
||||
ArrayList<BakedQuad> 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;
|
||||
}
|
||||
|
|
|
@ -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<BakedQuad> getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOff) {
|
||||
public List<BakedQuad> getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, float offset) {
|
||||
ArrayList<BakedQuad> 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;
|
||||
}
|
||||
|
|
|
@ -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<BakedQuad> getQuads(Block aBlock, BlockPos blockPos, EnumFacing side, int tintOffset) {
|
||||
public List<BakedQuad> 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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<FMLProxyPacket, GT_Packet>
|
||||
implements IGT_NetworkHandler {
|
||||
|
||||
private final EnumMap<Side, FMLEmbeddedChannel> 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<Object> 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<Object> 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<GT_Packet> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<Runnable> mList = new CopyOnWriteArrayList<>();
|
||||
public boolean mIsGenerating = false;
|
||||
//public List<Runnable> mList = new CopyOnWriteArrayList<>();
|
||||
//public boolean mIsGenerating = false;
|
||||
|
||||
|
||||
public GT_Worldgenerator() {
|
||||
|
@ -44,15 +44,12 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
public static class WorldGenContainer
|
||||
implements Runnable {
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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<? extends ItemBlock> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ItemStack> 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<ItemStack> aList) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -5,52 +5,58 @@ 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 {
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GT_Packet_Ores extends GT_Packet {
|
||||
|
||||
private ArrayList<OreInfo> ores = new ArrayList<>();
|
||||
|
||||
private static class OreInfo {
|
||||
private int mX;
|
||||
private int mZ;
|
||||
private int mY;
|
||||
private short mMetaData;
|
||||
|
||||
public GT_Packet_Ores() {
|
||||
super(true);
|
||||
public OreInfo(BlockPos pos, short metadata) {
|
||||
mX = pos.getX();
|
||||
mY = pos.getY();
|
||||
mZ = pos.getZ();
|
||||
mMetaData = metadata;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] encode() {
|
||||
ByteArrayDataOutput tOut = ByteStreams.newDataOutput(12);
|
||||
private OreInfo() {}
|
||||
|
||||
public void encode(ByteBuf tOut) {
|
||||
tOut.writeInt(this.mX);
|
||||
tOut.writeShort(this.mY);
|
||||
tOut.writeInt(this.mZ);
|
||||
tOut.writeShort(this.mMetaData);
|
||||
|
||||
return tOut.toByteArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GT_Packet decode(ByteArrayDataInput aData) {
|
||||
return new GT_Packet_Ores(new BlockPos(aData.readInt(), aData.readShort(), aData.readInt()), aData.readShort());
|
||||
public void decode(ByteBuf buf) {
|
||||
mX = buf.readInt();
|
||||
mY = buf.readShort();
|
||||
mZ = buf.readInt();
|
||||
mMetaData = buf.readShort();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(IBlockAccess aWorld) {
|
||||
if (aWorld != null) {
|
||||
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) {
|
||||
|
@ -60,8 +66,40 @@ public class GT_Packet_Ores
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getPacketID() {
|
||||
return 3;
|
||||
|
||||
}
|
||||
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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,20 +51,26 @@ public class GT_TickHandler_Ores {
|
|||
|
||||
@SubscribeEvent
|
||||
public void onPlayerTick(TickEvent.PlayerTickEvent player) {
|
||||
if(player.side.isServer()) {
|
||||
EntityPlayer entityPlayer = player.player;
|
||||
World world = entityPlayer.worldObj;
|
||||
if(world.getWorldTime() % 40 == 0) {
|
||||
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<GT_TileEntity_Ores> ores = getChunkData(world.provider.getDimension(), offset);
|
||||
ores.removeIf(TileEntity::isInvalid);
|
||||
for(GT_TileEntity_Ores oresTile : ores) {
|
||||
if(!oresTile.isBlocked()) oresTile.sendPacket();
|
||||
for (GT_TileEntity_Ores oresTile : ores) {
|
||||
packet_ores.addPos(oresTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!packet_ores.isEmpty()) {
|
||||
GT_Values.NW.sendTo(packet_ores, (EntityPlayerMP) entityPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
|
||||
if(side != null) {
|
||||
GlStateManager.enableLighting();
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
ArrayList<BakedQuad> 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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue