Some networking work
This commit is contained in:
parent
860fecf668
commit
9566be0b45
17 changed files with 218 additions and 96 deletions
|
@ -31,7 +31,11 @@ import gregtechmod.common.items.GT_MetaBlock_Item;
|
||||||
import gregtechmod.common.items.GT_MetaMachine_Item;
|
import gregtechmod.common.items.GT_MetaMachine_Item;
|
||||||
import gregtechmod.common.items.GT_MetaOre_Item;
|
import gregtechmod.common.items.GT_MetaOre_Item;
|
||||||
import gregtechmod.common.items.GT_MetaStone1_Item;
|
import gregtechmod.common.items.GT_MetaStone1_Item;
|
||||||
|
import gregtechmod.common.network.GT_PacketHandler;
|
||||||
|
import gregtechmod.common.network.packet.GT_Packet;
|
||||||
import gregtechmod.common.render.GT_Block_Renderer;
|
import gregtechmod.common.render.GT_Block_Renderer;
|
||||||
|
import gregtechmod.common.tileentities.GT_TileEntity_LightSource;
|
||||||
|
import gregtechmod.common.tileentities.GT_TileEntity_PlayerDetector;
|
||||||
import gregtechmod.loaders.load.GT_CircuitBehaviorLoad;
|
import gregtechmod.loaders.load.GT_CircuitBehaviorLoad;
|
||||||
import gregtechmod.loaders.load.GT_DictRegistratorPostItem;
|
import gregtechmod.loaders.load.GT_DictRegistratorPostItem;
|
||||||
import gregtechmod.loaders.load.GT_DictRegistratorPreItem;
|
import gregtechmod.loaders.load.GT_DictRegistratorPreItem;
|
||||||
|
@ -220,6 +224,7 @@ public class GT_Mod implements IGT_Mod, IGT_RecipeAdder {
|
||||||
GregTech_API.sPreloadStarted = true;
|
GregTech_API.sPreloadStarted = true;
|
||||||
|
|
||||||
new GT_InitHardCodedCapeList().run();
|
new GT_InitHardCodedCapeList().run();
|
||||||
|
new GT_PacketHandler().run();
|
||||||
|
|
||||||
GT_Log.log.info("GT_Mod: Creating Config Object.");
|
GT_Log.log.info("GT_Mod: Creating Config Object.");
|
||||||
GregTech_API.sConfiguration = new GT_Config(tConfig1, tConfig2, tConfig3);
|
GregTech_API.sConfiguration = new GT_Config(tConfig1, tConfig2, tConfig3);
|
||||||
|
@ -518,10 +523,10 @@ public class GT_Mod implements IGT_Mod, IGT_RecipeAdder {
|
||||||
// GameRegistry.registerTileEntity(GT_TileEntity_ComputerCube.class , GT_LanguageManager.mNameList1[ 4]);
|
// GameRegistry.registerTileEntity(GT_TileEntity_ComputerCube.class , GT_LanguageManager.mNameList1[ 4]);
|
||||||
// GameRegistry.registerTileEntity(GT_TileEntity_Sonictron.class , GT_LanguageManager.mNameList1[ 6]);
|
// GameRegistry.registerTileEntity(GT_TileEntity_Sonictron.class , GT_LanguageManager.mNameList1[ 6]);
|
||||||
// GameRegistry.registerTileEntity(GT_TileEntity_Superconductor.class , GT_LanguageManager.mNameList1[12]);
|
// GameRegistry.registerTileEntity(GT_TileEntity_Superconductor.class , GT_LanguageManager.mNameList1[12]);
|
||||||
// GameRegistry.registerTileEntity(GT_TileEntity_PlayerDetector.class , GT_LanguageManager.mNameList1[13]);
|
GameRegistry.registerTileEntity(GT_TileEntity_PlayerDetector.class , GT_LanguageManager.mNameList1[13]);
|
||||||
// GameRegistry.registerTileEntity(GT_TileEntity_LightSource.class , "GT_LightSource");
|
GameRegistry.registerTileEntity(GT_TileEntity_LightSource.class , "GT_LightSource");
|
||||||
|
|
||||||
// GameRegistry.registerTileEntity(GregTech_API.constructBaseMetaTileEntity().getClass(), "MetatileEntity");
|
GameRegistry.registerTileEntity(GregTech_API.constructBaseMetaTileEntity().getClass(), "MetatileEntity");
|
||||||
// GameRegistry.registerTileEntity(BaseMetaPipeEntity.class, "MetaPipeEntity");
|
// GameRegistry.registerTileEntity(BaseMetaPipeEntity.class, "MetaPipeEntity");
|
||||||
|
|
||||||
GT_Log.log.info("GT_Mod: Testing BaseMetaTileEntity.");
|
GT_Log.log.info("GT_Mod: Testing BaseMetaTileEntity.");
|
||||||
|
@ -1145,7 +1150,7 @@ public class GT_Mod implements IGT_Mod, IGT_RecipeAdder {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean allowPacketToBeSent(Packet aPacket, EntityPlayerMP aPlayer) {
|
public boolean allowPacketToBeSent(GT_Packet aPacket, EntityPlayerMP aPlayer) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package gregtechmod.api.interfaces;
|
package gregtechmod.api.interfaces;
|
||||||
|
|
||||||
|
import gregtechmod.common.network.packet.GT_Packet;
|
||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.network.Packet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface used by the Mods Main Class to reference to internals.
|
* Interface used by the Mods Main Class to reference to internals.
|
||||||
|
@ -12,7 +12,7 @@ public interface IGT_Mod {
|
||||||
/**
|
/**
|
||||||
* Just checks if said Packet should be sent to the Client. Currently does nothing important.
|
* Just checks if said Packet should be sent to the Client. Currently does nothing important.
|
||||||
*/
|
*/
|
||||||
public boolean allowPacketToBeSent(Packet aPacket, EntityPlayerMP aPlayer);
|
public boolean allowPacketToBeSent(GT_Packet aPacket, EntityPlayerMP aPlayer);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This means that Server specific Basefiles are definitely existing! Not if the World is actually server side or not!
|
* This means that Server specific Basefiles are definitely existing! Not if the World is actually server side or not!
|
||||||
|
|
|
@ -8,6 +8,8 @@ import gregtechmod.api.interfaces.IGregTechTileEntity;
|
||||||
import gregtechmod.api.interfaces.IMachineProgress;
|
import gregtechmod.api.interfaces.IMachineProgress;
|
||||||
import gregtechmod.api.interfaces.IUpgradableMachine;
|
import gregtechmod.api.interfaces.IUpgradableMachine;
|
||||||
import gregtechmod.api.items.GT_EnergyArmor_Item;
|
import gregtechmod.api.items.GT_EnergyArmor_Item;
|
||||||
|
import gregtechmod.common.network.GT_PacketHandler;
|
||||||
|
import gregtechmod.common.network.packet.GT_SoundPacket;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
@ -41,10 +43,8 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.nbt.NBTTagString;
|
import net.minecraft.nbt.NBTTagString;
|
||||||
import net.minecraft.network.Packet;
|
|
||||||
import net.minecraft.network.play.server.S07PacketRespawn;
|
import net.minecraft.network.play.server.S07PacketRespawn;
|
||||||
import net.minecraft.network.play.server.S1DPacketEntityEffect;
|
import net.minecraft.network.play.server.S1DPacketEntityEffect;
|
||||||
import net.minecraft.network.play.server.S3FPacketCustomPayload;
|
|
||||||
import net.minecraft.potion.PotionEffect;
|
import net.minecraft.potion.PotionEffect;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
@ -65,9 +65,6 @@ import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
import cpw.mods.fml.common.gameevent.PlayerEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -679,23 +676,23 @@ public class GT_Utility {
|
||||||
|
|
||||||
public static boolean sendSoundToPlayers(World aWorld, String aSoundName, float aSoundStrength, float aSoundModulation, int aX, int aY, int aZ) {
|
public static boolean sendSoundToPlayers(World aWorld, String aSoundName, float aSoundStrength, float aSoundModulation, int aX, int aY, int aZ) {
|
||||||
if (aSoundName == null || aSoundName.equals("") || aWorld == null || aWorld.isRemote) return false;
|
if (aSoundName == null || aSoundName.equals("") || aWorld == null || aWorld.isRemote) return false;
|
||||||
ByteArrayDataOutput tOut = ByteStreams.newDataOutput();
|
// ByteArrayDataOutput tOut = ByteStreams.newDataOutput();
|
||||||
|
//
|
||||||
tOut.writeInt(aX);
|
// tOut.writeInt(aX);
|
||||||
tOut.writeShort(aY);
|
// tOut.writeShort(aY);
|
||||||
tOut.writeInt(aZ);
|
// tOut.writeInt(aZ);
|
||||||
|
//
|
||||||
tOut.writeUTF(aSoundName);
|
// tOut.writeUTF(aSoundName);
|
||||||
tOut.writeFloat(aSoundStrength);
|
// tOut.writeFloat(aSoundStrength);
|
||||||
tOut.writeFloat(aSoundModulation < 0 ? (1.0F + (aWorld.rand.nextFloat() - aWorld.rand.nextFloat()) * 0.2F) * 0.7F : aSoundModulation);
|
// tOut.writeFloat(aSoundModulation < 0 ? (1.0F + (aWorld.rand.nextFloat() - aWorld.rand.nextFloat()) * 0.2F) * 0.7F : aSoundModulation);
|
||||||
|
aSoundModulation = aSoundModulation < 0 ? (1.0F + (aWorld.rand.nextFloat() - aWorld.rand.nextFloat()) * 0.2F) * 0.7F : aSoundModulation;
|
||||||
S3FPacketCustomPayload tPacket = new S3FPacketCustomPayload(GregTech_API.SOUND_PACKET_CHANNEL, tOut.toByteArray());
|
GT_SoundPacket tPacket = new GT_SoundPacket(aSoundName, aX, aY, aZ, aSoundStrength, aSoundModulation);
|
||||||
sendPacketToAllPlayersInRange(aWorld, tPacket, aX, aZ);
|
sendPacketToAllPlayersInRange(aWorld, tPacket, aX, aZ);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendPacketToAllPlayersInRange(World aWorld, Packet aPacket, int aX, int aZ) {
|
public static void sendPacketToAllPlayersInRange(World aWorld, GT_SoundPacket aPacket, int aX, int aZ) {
|
||||||
for (Object tObject : aWorld.playerEntities) {
|
for (Object tObject : aWorld.playerEntities) {
|
||||||
if (tObject instanceof EntityPlayerMP) {
|
if (tObject instanceof EntityPlayerMP) {
|
||||||
EntityPlayerMP tPlayer = (EntityPlayerMP)tObject;
|
EntityPlayerMP tPlayer = (EntityPlayerMP)tObject;
|
||||||
|
@ -703,7 +700,7 @@ public class GT_Utility {
|
||||||
Chunk tChunk = aWorld.getChunkFromBlockCoords(aX, aZ);
|
Chunk tChunk = aWorld.getChunkFromBlockCoords(aX, aZ);
|
||||||
if (tPlayer.getServerForPlayer().getPlayerManager().isPlayerWatchingChunk(tPlayer, tChunk.xPosition, tChunk.zPosition)) {
|
if (tPlayer.getServerForPlayer().getPlayerManager().isPlayerWatchingChunk(tPlayer, tChunk.xPosition, tChunk.zPosition)) {
|
||||||
if (GregTech_API.DEBUG_MODE) GT_Log.log.debug("sent Packet to " + tPlayer.getDisplayName());
|
if (GregTech_API.DEBUG_MODE) GT_Log.log.debug("sent Packet to " + tPlayer.getDisplayName());
|
||||||
tPlayer.playerNetServerHandler.sendPacket(aPacket);
|
GT_PacketHandler.SOUND_PACKET_CHANNEL.sendTo(aPacket, tPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -3,6 +3,10 @@ package gregtechmod.common;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
public class GT_IteratorRandom extends Random {
|
public class GT_IteratorRandom extends Random {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = -2001727503848927794L;
|
||||||
public int mIterationStep = Integer.MAX_VALUE;
|
public int mIterationStep = Integer.MAX_VALUE;
|
||||||
|
|
||||||
@Override public int nextInt(int aParameter) {
|
@Override public int nextInt(int aParameter) {
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
package gregtechmod.common;
|
|
||||||
|
|
||||||
import gregtechmod.api.GregTech_API;
|
|
||||||
import gregtechmod.api.metatileentity.BaseMetaPipeEntity;
|
|
||||||
import gregtechmod.api.metatileentity.BaseMetaTileEntity;
|
|
||||||
import gregtechmod.api.util.GT_Log;
|
|
||||||
import gregtechmod.api.util.GT_Utility;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
|
||||||
import net.minecraft.network.INetworkManager;
|
|
||||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.IPacketHandler;
|
|
||||||
import cpw.mods.fml.common.network.Player;
|
|
||||||
|
|
||||||
public class GT_PacketHandler implements IPacketHandler {
|
|
||||||
@Override
|
|
||||||
public void onPacketData(INetworkManager aManager, Packet250CustomPayload aPacket, Player aPlayer) {
|
|
||||||
try {
|
|
||||||
if (aPacket.channel.equals(GregTech_API.TILEENTITY_PACKET_CHANNEL)) {
|
|
||||||
ByteArrayDataInput tIn = ByteStreams.newDataInput(aPacket.data);
|
|
||||||
int tX = tIn.readInt(), tY = tIn.readShort(), tZ = tIn.readInt();
|
|
||||||
if (aPlayer != null && aPlayer instanceof EntityPlayer) {
|
|
||||||
if (GregTech_API.DEBUG_MODE && (((EntityPlayer)aPlayer).username.equals("Player") || ((EntityPlayer)aPlayer).username.equals("GregoriusT"))) GT_Log.out.println("Received initial MetaTileEntity Data: " + aPacket.length + " Bytes @ (" + tX + ";" + tY + ";" + tZ + ") during Tick: " + GregTech_API.sClientTickCounter);
|
|
||||||
TileEntity tTileEntity = ((EntityPlayer)aPlayer).worldObj.getBlockTileEntity(tX, tY, tZ);
|
|
||||||
if (tTileEntity != null) {
|
|
||||||
if (tTileEntity instanceof BaseMetaTileEntity) ((BaseMetaTileEntity)tTileEntity).receiveMetaTileEntityData(tIn.readShort(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readByte(), tIn.readByte(), tIn.readByte(), tIn.readByte());
|
|
||||||
else if (tTileEntity instanceof BaseMetaPipeEntity) ((BaseMetaPipeEntity)tTileEntity).receiveMetaTileEntityData(tIn.readShort(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readByte(), tIn.readByte(), tIn.readByte(), tIn.readByte());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (aPacket.channel.equals(GregTech_API.SOUND_PACKET_CHANNEL)) {
|
|
||||||
ByteArrayDataInput tIn = ByteStreams.newDataInput(aPacket.data);
|
|
||||||
int tX = tIn.readInt(), tY = tIn.readShort(), tZ = tIn.readInt();
|
|
||||||
if (aPlayer != null && aPlayer instanceof EntityPlayer) {
|
|
||||||
GT_Utility.doSoundAtClient(tIn.readUTF(), tIn.readFloat(), tIn.readFloat(), tX, tY, tZ);
|
|
||||||
}
|
|
||||||
} else if (aPacket.channel.equals(GregTech_API.GENERIC_CHANNEL)) {
|
|
||||||
if (GregTech_API.DEBUG_MODE) GT_Log.out.println("Tick " + GregTech_API.sClientTickCounter + " @ " + aPacket.channel + " -> " + aPacket.data.length + " Bytes");
|
|
||||||
} else {
|
|
||||||
GT_Log.out.println("Tick " + GregTech_API.sClientTickCounter + " @ " + aPacket.channel + " -> " + aPacket.data.length + " Bytes");
|
|
||||||
}
|
|
||||||
} catch(Throwable e) {
|
|
||||||
e.printStackTrace(GT_Log.err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -7,7 +7,6 @@ import gregtechmod.api.world.GT_Worldgen;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
|
|
|
@ -840,8 +840,7 @@ public class GT_BlockMetaID_Machine extends BlockContainer implements IDebugable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World aWorld, int meta) { // TODO: there wasnt meta before
|
public TileEntity createNewTileEntity(World aWorld, int meta) { // TODO: there wasnt meta before
|
||||||
// return GregTech_API.constructBaseMetaTileEntity(); // FIXME
|
return GregTech_API.constructBaseMetaTileEntity();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -79,8 +79,7 @@ public class GT_Block_LightSource extends BlockContainer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TileEntity createNewTileEntity(World aWorld, int meta) {
|
public TileEntity createNewTileEntity(World aWorld, int meta) {
|
||||||
// return new GT_TileEntity_LightSource(); // TODO: Tile entities
|
return new GT_TileEntity_LightSource();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package gregtechmod.common.network;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||||
|
import gregtechmod.api.GregTech_API;
|
||||||
|
import gregtechmod.api.util.GT_Log;
|
||||||
|
import gregtechmod.api.util.GT_Utility;
|
||||||
|
import gregtechmod.common.network.packet.GT_Packet;
|
||||||
|
import gregtechmod.common.network.packet.GT_SoundPacket;
|
||||||
|
import gregtechmod.common.network.packet.GT_TileEntityPacket;
|
||||||
|
|
||||||
|
public abstract class GT_NetworkHandler<T extends GT_Packet> implements IMessageHandler<T, IMessage> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IMessage onMessage(T message, MessageContext ctx) {
|
||||||
|
if (message instanceof GT_TileEntityPacket) {
|
||||||
|
// TODO Packets
|
||||||
|
} else if (message instanceof GT_SoundPacket) {
|
||||||
|
GT_SoundPacket sound = (GT_SoundPacket) message;
|
||||||
|
if (GT_Utility.sCurrentPlayer != null) {
|
||||||
|
GT_Utility.doSoundAtClient(sound.aSoundName, sound.aSoundStrength, sound.aSoundModulation, sound.aX, sound.aY, sound.aZ);
|
||||||
|
}
|
||||||
|
} else if (message instanceof GT_Packet) {
|
||||||
|
if (GregTech_API.DEBUG_MODE) GT_Log.log.info("Tick " + GregTech_API.sClientTickCounter + " Bytes: " + message.data.capacity());
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// public void onPacketData(INetworkManager aManager, Packet250CustomPayload aPacket, Player aPlayer) {
|
||||||
|
// if (aPacket.channel.equals(GregTech_API.TILEENTITY_PACKET_CHANNEL)) {
|
||||||
|
// ByteArrayDataInput tIn = ByteStreams.newDataInput(aPacket.data);
|
||||||
|
// int tX = tIn.readInt(), tY = tIn.readShort(), tZ = tIn.readInt();
|
||||||
|
// if (aPlayer != null && aPlayer instanceof EntityPlayer) {
|
||||||
|
// if (GregTech_API.DEBUG_MODE && (((EntityPlayer)aPlayer).username.equals("Player") || ((EntityPlayer)aPlayer).username.equals("GregoriusT"))) GT_Log.out.println("Received initial MetaTileEntity Data: " + aPacket.length + " Bytes @ (" + tX + ";" + tY + ";" + tZ + ") during Tick: " + GregTech_API.sClientTickCounter);
|
||||||
|
// TileEntity tTileEntity = ((EntityPlayer)aPlayer).worldObj.getBlockTileEntity(tX, tY, tZ);
|
||||||
|
// if (tTileEntity != null) {
|
||||||
|
// if (tTileEntity instanceof BaseMetaTileEntity) ((BaseMetaTileEntity)tTileEntity).receiveMetaTileEntityData(tIn.readShort(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readByte(), tIn.readByte(), tIn.readByte(), tIn.readByte());
|
||||||
|
// else if (tTileEntity instanceof BaseMetaPipeEntity) ((BaseMetaPipeEntity)tTileEntity).receiveMetaTileEntityData(tIn.readShort(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readInt(), tIn.readByte(), tIn.readByte(), tIn.readByte(), tIn.readByte());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package gregtechmod.common.network;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||||
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import gregtechmod.common.network.packet.GT_Packet;
|
||||||
|
import gregtechmod.common.network.packet.GT_SoundPacket;
|
||||||
|
import gregtechmod.common.network.packet.GT_TileEntityPacket;
|
||||||
|
|
||||||
|
public final class GT_PacketHandler implements Runnable {
|
||||||
|
private static byte discriminator = 0;
|
||||||
|
|
||||||
|
public final static SimpleNetworkWrapper GENERIC_CHANNEL;
|
||||||
|
public final static SimpleNetworkWrapper TILEENTITY_PACKET_CHANNEL;
|
||||||
|
public final static SimpleNetworkWrapper SOUND_PACKET_CHANNEL;
|
||||||
|
|
||||||
|
static {
|
||||||
|
GENERIC_CHANNEL = NetworkRegistry.INSTANCE.newSimpleChannel("gregtech");
|
||||||
|
TILEENTITY_PACKET_CHANNEL = NetworkRegistry.INSTANCE.newSimpleChannel("GTTile");
|
||||||
|
SOUND_PACKET_CHANNEL = NetworkRegistry.INSTANCE.newSimpleChannel("GTSound");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
GT_PacketHandler.registerClientMessage(GENERIC_CHANNEL, GT_Packet.class);
|
||||||
|
GT_PacketHandler.registerClientMessage(TILEENTITY_PACKET_CHANNEL, GT_TileEntityPacket.class);
|
||||||
|
GT_PacketHandler.registerClientMessage(SOUND_PACKET_CHANNEL, GT_SoundPacket.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static <T extends GT_Packet> void registerServerMessage(SimpleNetworkWrapper channel, Class<T> type) {
|
||||||
|
GT_PacketHandler.register(channel, type, Side.SERVER);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static <T extends GT_Packet> void registerClientMessage(SimpleNetworkWrapper channel, Class<T> type) {
|
||||||
|
GT_PacketHandler.register(channel, type, Side.CLIENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T extends GT_Packet> void register(SimpleNetworkWrapper channel, Class<T> type, Side side) {
|
||||||
|
channel.registerMessage(new GT_NetworkHandler<T>() {}, type, discriminator++, side);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package gregtechmod.common.network.packet;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public abstract class GT_Packet implements IMessage {
|
||||||
|
public ByteBuf data;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
this.data = buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
this.data = buf;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package gregtechmod.common.network.packet;
|
||||||
|
|
||||||
|
import cpw.mods.fml.common.network.ByteBufUtils;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public class GT_SoundPacket extends GT_Packet {
|
||||||
|
public int aX;
|
||||||
|
public int aY;
|
||||||
|
public int aZ;
|
||||||
|
public String aSoundName;
|
||||||
|
public float aSoundStrength;
|
||||||
|
public float aSoundModulation;
|
||||||
|
|
||||||
|
public GT_SoundPacket() {}
|
||||||
|
|
||||||
|
public GT_SoundPacket(String soundName, int x, int y, int z, float volume, float modulation) {
|
||||||
|
this.aSoundName = soundName;
|
||||||
|
this.aX = x;
|
||||||
|
this.aY = y;
|
||||||
|
this.aZ = z;
|
||||||
|
this.aSoundStrength = volume;
|
||||||
|
this.aSoundModulation = modulation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
aX = buf.readInt();
|
||||||
|
aY = buf.readInt();
|
||||||
|
aZ = buf.readInt();
|
||||||
|
aSoundStrength = buf.readFloat();
|
||||||
|
aSoundModulation = buf.readFloat();
|
||||||
|
aSoundName = ByteBufUtils.readUTF8String(buf);
|
||||||
|
super.fromBytes(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
buf.writeInt(aX);
|
||||||
|
buf.writeInt(aY);
|
||||||
|
buf.writeInt(aZ);
|
||||||
|
buf.writeFloat(aSoundStrength);
|
||||||
|
buf.writeFloat(aSoundModulation);
|
||||||
|
ByteBufUtils.writeUTF8String(buf, aSoundName);
|
||||||
|
super.toBytes(buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package gregtechmod.common.network.packet;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
public class GT_TileEntityPacket extends GT_Packet {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fromBytes(ByteBuf buf) {
|
||||||
|
super.fromBytes(buf);
|
||||||
|
// FIXME Packets
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void toBytes(ByteBuf buf) {
|
||||||
|
super.toBytes(buf);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -22,8 +22,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Icon;
|
import net.minecraft.util.IIcon;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.FluidTankInfo;
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
|
@ -1303,7 +1302,7 @@ public class GT_TileEntityMetaID_Machine extends BaseTileEntity implements IGreg
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Icon getTextureIcon(byte aSide, byte aMeta) {
|
public IIcon getTextureIcon(byte aSide, byte aMeta) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,17 +7,14 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.MathHelper;
|
import net.minecraft.util.MathHelper;
|
||||||
|
|
||||||
public class GT_TileEntity_LightSource extends TileEntity {
|
public class GT_TileEntity_LightSource extends TileEntity {
|
||||||
|
|
||||||
private int mTickTimer = 0;
|
private int mTickTimer = 0;
|
||||||
|
|
||||||
public GT_TileEntity_LightSource() {
|
public GT_TileEntity_LightSource() {}
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateEntity() {
|
public void updateEntity() {
|
||||||
if (worldObj.isRemote) return;
|
if (worldObj.isRemote) return;
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Iterator<EntityPlayer> tIterator = worldObj.playerEntities.iterator();
|
Iterator<EntityPlayer> tIterator = worldObj.playerEntities.iterator();
|
||||||
|
|
||||||
boolean temp = true;
|
boolean temp = true;
|
||||||
|
|
|
@ -42,6 +42,7 @@ public class GT_TileEntity_PlayerDetector extends GT_TileEntityMetaID_Machine {
|
||||||
mActive = false;
|
mActive = false;
|
||||||
mRedstoneStrength = 0;
|
mRedstoneStrength = 0;
|
||||||
if (decreaseStoredEnergy(50, false)) {
|
if (decreaseStoredEnergy(50, false)) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
Iterator<EntityPlayer> tIterator = worldObj.playerEntities.iterator();
|
Iterator<EntityPlayer> tIterator = worldObj.playerEntities.iterator();
|
||||||
while (tIterator.hasNext()) {
|
while (tIterator.hasNext()) {
|
||||||
EntityPlayer tPlayer = tIterator.next();
|
EntityPlayer tPlayer = tIterator.next();
|
||||||
|
|
|
@ -28,12 +28,12 @@ public class GT_TileEntity_Superconductor extends GT_TileEntityMetaID_Machine im
|
||||||
if (xCoord == 0 && yCoord == 0 && zCoord == 0) return 103;
|
if (xCoord == 0 && yCoord == 0 && zCoord == 0) return 103;
|
||||||
|
|
||||||
boolean[] tConnectedSides = {
|
boolean[] tConnectedSides = {
|
||||||
worldObj.getBlockTileEntity(xCoord, yCoord-1, zCoord) instanceof IEnergyTile,
|
worldObj.getTileEntity(xCoord, yCoord-1, zCoord) instanceof IEnergyTile,
|
||||||
worldObj.getBlockTileEntity(xCoord, yCoord+1, zCoord) instanceof IEnergyTile,
|
worldObj.getTileEntity(xCoord, yCoord+1, zCoord) instanceof IEnergyTile,
|
||||||
worldObj.getBlockTileEntity(xCoord+1, yCoord, zCoord) instanceof IEnergyTile,
|
worldObj.getTileEntity(xCoord+1, yCoord, zCoord) instanceof IEnergyTile,
|
||||||
worldObj.getBlockTileEntity(xCoord, yCoord, zCoord+1) instanceof IEnergyTile,
|
worldObj.getTileEntity(xCoord, yCoord, zCoord+1) instanceof IEnergyTile,
|
||||||
worldObj.getBlockTileEntity(xCoord-1, yCoord, zCoord) instanceof IEnergyTile,
|
worldObj.getTileEntity(xCoord-1, yCoord, zCoord) instanceof IEnergyTile,
|
||||||
worldObj.getBlockTileEntity(xCoord, yCoord, zCoord-1) instanceof IEnergyTile
|
worldObj.getTileEntity(xCoord, yCoord, zCoord-1) instanceof IEnergyTile
|
||||||
};
|
};
|
||||||
|
|
||||||
switch (aSide) {
|
switch (aSide) {
|
||||||
|
@ -157,15 +157,15 @@ public class GT_TileEntity_Superconductor extends GT_TileEntityMetaID_Machine im
|
||||||
return 0.0D;
|
return 0.0D;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getInsulationEnergyAbsorption() {
|
public double getInsulationEnergyAbsorption() {
|
||||||
return 8192;
|
return 8192;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getInsulationBreakdownEnergy() {
|
public double getInsulationBreakdownEnergy() {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getConductorBreakdownEnergy() {
|
public double getConductorBreakdownEnergy() {
|
||||||
return Integer.MAX_VALUE;
|
return Integer.MAX_VALUE;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue