Trying to fix the sync issue
This commit is contained in:
parent
4fcdf22220
commit
8055546675
7 changed files with 125 additions and 5 deletions
|
@ -181,7 +181,7 @@ public class RecipeCrafter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void useAllInputs() {
|
public void useAllInputs() {
|
||||||
if (currentRecipe == null) {
|
if (currentRecipe == null || !parentTile.getWorldObj().isRemote) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (ItemStack input : currentRecipe.getInputs()) {
|
for (ItemStack input : currentRecipe.getInputs()) {
|
||||||
|
|
|
@ -20,9 +20,8 @@ public class PacketHandler extends
|
||||||
FMLIndexedMessageToMessageCodec<SimplePacket> {
|
FMLIndexedMessageToMessageCodec<SimplePacket> {
|
||||||
private static EnumMap<Side, FMLEmbeddedChannel> channels;
|
private static EnumMap<Side, FMLEmbeddedChannel> channels;
|
||||||
|
|
||||||
public PacketHandler()
|
public PacketHandler() {
|
||||||
{
|
addDiscriminator(0, PacketSync.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EnumMap<Side, FMLEmbeddedChannel> getChannels()
|
public static EnumMap<Side, FMLEmbeddedChannel> getChannels()
|
||||||
|
|
69
src/main/java/techreborn/packets/PacketSync.java
Normal file
69
src/main/java/techreborn/packets/PacketSync.java
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -82,5 +82,4 @@ public class TileAlloyFurnace extends TileMachineBase implements IWrenchable {
|
||||||
inventory.writeToNBT(tagCompound);
|
inventory.writeToNBT(tagCompound);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,20 @@ public class TileAlloySmelter extends TileMachineBase implements IWrenchable, IE
|
||||||
crafter.writeToNBT(tagCompound);
|
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);
|
||||||
|
energy.writeToNBT(tagCompound);
|
||||||
|
crafter.writeToNBT(tagCompound);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate(){
|
public void invalidate(){
|
||||||
energy.invalidate();
|
energy.invalidate();
|
||||||
|
|
|
@ -8,6 +8,8 @@ import net.minecraft.network.Packet;
|
||||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import techreborn.packets.PacketHandler;
|
import techreborn.packets.PacketHandler;
|
||||||
|
import techreborn.packets.PacketSync;
|
||||||
|
import techreborn.packets.SimplePacket;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -33,6 +35,7 @@ public class TileMachineBase extends TileEntity {
|
||||||
|
|
||||||
public void syncWithAll() {
|
public void syncWithAll() {
|
||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
|
//PacketHandler.sendPacketToAllPlayers(getSyncPacket());
|
||||||
PacketHandler.sendPacketToAllPlayers(getDescriptionPacket(),
|
PacketHandler.sendPacketToAllPlayers(getDescriptionPacket(),
|
||||||
worldObj);
|
worldObj);
|
||||||
} else {
|
} else {
|
||||||
|
@ -42,6 +45,19 @@ public class TileMachineBase extends TileEntity {
|
||||||
ticksSinceLastSync = 0;
|
ticksSinceLastSync = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Packet getDescriptionPacket2() {
|
||||||
|
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() {
|
public Packet getDescriptionPacket() {
|
||||||
NBTTagCompound nbtTag = new NBTTagCompound();
|
NBTTagCompound nbtTag = new NBTTagCompound();
|
||||||
writeToNBT(nbtTag);
|
writeToNBT(nbtTag);
|
||||||
|
@ -56,5 +72,13 @@ public class TileMachineBase extends TileEntity {
|
||||||
readFromNBT(packet.func_148857_g());
|
readFromNBT(packet.func_148857_g());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void readSyncFromNBT(NBTTagCompound tagCompound) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeSyncToNBT(NBTTagCompound tagCompound) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
15
src/main/java/techreborn/util/ClientUtil.java
Normal file
15
src/main/java/techreborn/util/ClientUtil.java
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue