added it for all the machines, can you test? Im about to give up on it ;(

This commit is contained in:
modmuss50 2015-05-27 12:28:13 +01:00
parent bed71bd732
commit 046b7d7375
16 changed files with 95 additions and 113 deletions

View file

@ -21,7 +21,6 @@ public class PacketHandler extends
private static EnumMap<Side, FMLEmbeddedChannel> channels;
public PacketHandler() {
addDiscriminator(0, PacketSync.class);
}
public static EnumMap<Side, FMLEmbeddedChannel> getChannels()

View file

@ -1,69 +0,0 @@
package techreborn.packets;
import io.netty.buffer.ByteBuf;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTSizeTracker;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import techreborn.tiles.TileMachineBase;
import techreborn.util.ClientUtil;
import techreborn.util.LogHelper;
import java.io.IOException;
public class PacketSync extends SimplePacket {
private NBTTagCompound nbttagcompound;
private int x, y, z;
public PacketSync() {
}
public PacketSync(NBTTagCompound nbttagcompound, int x, int y, int z) {
this.nbttagcompound = nbttagcompound;
this.x = x;
this.y = y;
this.z = z;
}
@Override
public void writeData(ByteBuf data) throws IOException{
try {
byte[] compressed = CompressedStreamTools.compress(nbttagcompound);
if (compressed.length > 65535) {
LogHelper.error("NBT data is too large (" + compressed.length + " > 65535)! Please report!");
}
data.writeShort(compressed.length);
data.writeBytes(compressed);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void readData(ByteBuf data) throws IOException{
int length = data.readUnsignedShort();
byte[] compressed = new byte[length];
data.readBytes(compressed);
try {
this.nbttagcompound = CompressedStreamTools.func_152457_a(compressed, NBTSizeTracker.field_152451_a);
} catch (IOException e) {
e.printStackTrace();
}
}
public NBTTagCompound getTagCompound() {
return this.nbttagcompound;
}
@Override
public void execute() {
TileEntity tile = ClientUtil.getWorld().getTileEntity(x, y, z);
if(tile instanceof TileMachineBase){
((TileMachineBase) tile).readSyncFromNBT(getTagCompound());
}
}
}

View file

@ -91,13 +91,6 @@ public class TileAlloySmelter extends TileMachineBase implements IWrenchable, IE
crafter.writeToNBT(tagCompound);
}
@Override
public void readSyncFromNBT(NBTTagCompound tagCompound) {
super.readSyncFromNBT(tagCompound);
energy.readFromNBT(tagCompound);
crafter.readFromNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);

View file

@ -102,6 +102,14 @@ public class TileAssemblingMachine extends TileMachineBase implements IWrenchabl
crafter.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
@Override
public void invalidate()
{

View file

@ -109,6 +109,14 @@ public class TileCentrifuge extends TileMachineBase implements IWrenchable, IEn
crafter.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
@Override
public void invalidate()
{

View file

@ -102,6 +102,14 @@ public class TileChemicalReactor extends TileMachineBase implements IWrenchable,
crafter.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
@Override
public void invalidate()
{

View file

@ -99,6 +99,15 @@ public class TileGrinder extends TileMachineBase implements IWrenchable, IEnergy
crafter.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
tank.writeToNBT(tagCompound);
}
@Override
public void invalidate() {
energy.invalidate();

View file

@ -123,6 +123,13 @@ public class TileHeatGenerator extends TileMachineBase implements IWrenchable, I
energy.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
}
@Override
public void addWailaInfo(List<String> info)
{

View file

@ -95,6 +95,14 @@ public class TileImplosionCompressor extends TileMachineBase implements IWrencha
crafter.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
@Override
public void addWailaInfo(List<String> info)
{

View file

@ -100,6 +100,14 @@ public class TileIndustrialElectrolyzer extends TileMachineBase implements IWren
energy.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
@Override
public void invalidate()
{

View file

@ -104,6 +104,14 @@ public class TileIndustrialSawmill extends TileMachineBase implements IWrenchabl
crafter.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
@Override
public void invalidate()
{

View file

@ -101,6 +101,14 @@ public class TileLathe extends TileMachineBase implements IWrenchable, IEnergyTi
crafter.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
@Override
public void invalidate()
{

View file

@ -8,8 +8,6 @@ import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import techreborn.packets.PacketHandler;
import techreborn.packets.PacketSync;
import techreborn.packets.SimplePacket;
import java.util.List;
@ -35,8 +33,7 @@ public class TileMachineBase extends TileEntity {
public void syncWithAll() {
if (!worldObj.isRemote) {
//PacketHandler.sendPacketToAllPlayers(getSyncPacket());
PacketHandler.sendPacketToAllPlayers(getDescriptionPacket2(),
PacketHandler.sendPacketToAllPlayers(getSyncPacket(),
worldObj);
} else {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
@ -45,19 +42,13 @@ public class TileMachineBase extends TileEntity {
ticksSinceLastSync = 0;
}
public Packet getDescriptionPacket2() {
public Packet getSyncPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeSyncToNBT(nbtTag);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord,
this.zCoord, 1, nbtTag);
}
public SimplePacket getSyncPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeSyncToNBT(nbtTag);
return new PacketSync(nbtTag, xCoord, yCoord, zCoord);
}
public Packet getDescriptionPacket() {
NBTTagCompound nbtTag = new NBTTagCompound();
writeToNBT(nbtTag);
@ -72,10 +63,6 @@ public class TileMachineBase extends TileEntity {
readFromNBT(packet.func_148857_g());
}
public void readSyncFromNBT(NBTTagCompound tagCompound) {
}
public void writeSyncToNBT(NBTTagCompound tagCompound) {
}

View file

@ -83,6 +83,13 @@ public class TileMatterFabricator extends TileMachineBase implements IWrenchable
energy.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
}
@Override
public void invalidate()
{

View file

@ -101,6 +101,14 @@ public class TilePlateCuttingMachine extends TileMachineBase implements IWrencha
crafter.writeToNBT(tagCompound);
}
@Override
public void writeSyncToNBT(NBTTagCompound tagCompound) {
super.writeSyncToNBT(tagCompound);
energy.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
}
@Override
public void addWailaInfo(List<String> info)
{

View file

@ -1,15 +0,0 @@
package techreborn.util;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.world.World;
public class ClientUtil {
@SideOnly(Side.CLIENT)
public static World getWorld(){
return Minecraft.getMinecraft().theWorld;
}
}