zlappedx3 Posted June 3, 2016 Posted June 3, 2016 Posted ago, I post about time in world but now, I need Sync it, I can Sync IExtendedEntityProperties but i can't Sync WorldSavedData. You can do it ? public abstract class AbstractMessage<T extends AbstractMessage<T>> implements IMessage, IMessageHandler <T, IMessage> { protected abstract void read(PacketBuffer buffer) throws IOException; protected abstract void write(PacketBuffer buffer) throws IOException; public abstract void process(World world, Side side); protected boolean isValidOnSide(Side side) { return true; } protected boolean requiresMainThread() { return true; } @Override public void fromBytes(ByteBuf buffer) { try { read(new PacketBuffer(buffer)); } catch (IOException e) { throw Throwables.propagate(e); } } @Override public void toBytes(ByteBuf buffer) { try { write(new PacketBuffer(buffer)); } catch (IOException e) { throw Throwables.propagate(e); } } @Override public final IMessage onMessage(T msg, MessageContext ctx) { if (!msg.isValidOnSide(ctx.side)) { throw new RuntimeException("Invalid side " + ctx.side.name() + " for " + msg.getClass().getSimpleName()); } else if (msg.requiresMainThread()) { checkThreadAndEnqueue(msg, ctx); } else { msg.process(main.proxy.getPlayerEntity(ctx).worldObj, ctx.side); } return null; } private static final <T extends AbstractMessage<T>> void checkThreadAndEnqueue(final AbstractMessage<T> msg, final MessageContext ctx) { IThreadListener thread = main.proxy.getThreadFromContext(ctx); thread.addScheduledTask(new Runnable() { public void run() { msg.process(main.proxy.getPlayerEntity(ctx).worldObj, ctx.side); } }); } public static abstract class AbstractClientMessage<T extends AbstractMessage<T>> extends AbstractMessage<T> { @Override protected final boolean isValidOnSide(Side side) { return side.isClient(); } } } public class SyncWorldPropsMessage extends AbstractClientMessage<SyncWorldPropsMessage> { private NBTTagCompound data; public SyncWorldPropsMessage() {} public SyncWorldPropsMessage(World world) { data = new NBTTagCompound(); WorldData.forWorld(world).writeToNBT(data); } @Override protected void read(PacketBuffer buffer) throws IOException { data = buffer.readNBTTagCompoundFromBuffer(); } @Override protected void write(PacketBuffer buffer) throws IOException { buffer.writeNBTTagCompoundToBuffer(data); } @Override public void process(World world, Side side) { WorldData.forWorld(world).readFromNBT(data); } } public class WorldData extends WorldSavedData { final static String key = References.MODID; private NBTTagCompound data = new NBTTagCompound(); public WorldData(String tagName) { super(tagName); } public static WorldData forWorld(World world) { MapStorage storage = world.perWorldStorage; WorldData result = (WorldData)storage.loadData(WorldData.class, key); if (result == null) { result = new WorldData(key); storage.setData(key, result); } return result; } @Override public void readFromNBT(NBTTagCompound compound) { data = compound.getCompoundTag(key); } @Override public void writeToNBT(NBTTagCompound compound) { compound.setTag(key, data); } public NBTTagCompound getData() { return data; } } Quote
zlappedx3 Posted June 3, 2016 Author Posted June 3, 2016 it not have variable but i use tag.setString("5", "test"); by command and out in gui by mc.fontRenderer.drawString("" + tag.getString("5"), int, int, 0); Sorry if my English was not good. Quote
zlappedx3 Posted June 3, 2016 Author Posted June 3, 2016 I mean this code can use sync worldsavedata ? Quote
Draco18s Posted June 3, 2016 Posted June 3, 2016 Fix it first. Quote Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.