Jump to content

XiNiHa

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by XiNiHa

  1. After reading Actually Additions' world data code, I've decided to completely rewrite my WorldSavedData and packet code. Thanks for help!
  2. public class PlayerEventHandler { @SubscribeEvent public void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) { PacketHandler.INSTANCE.sendTo(new PacketMemoClient(true, WSDMemo.get(event.player.world).getMemos()), (EntityPlayerMP) event.player); } } public MemoItem[] getMemos() { Set<String> keySet = memos.getKeySet(); MemoItem[] items = new MemoItem[keySet.size()]; for (String key: keySet) { BlockPos pos = BlockPos.fromLong(Long.getLong(key)); // Crashed Line NBTTagCompound memo = memos.getCompoundTag(key); String text = memo.getString("text"); int color = memo.getInteger("color"); MemoItem item = new MemoItem(pos, text, color, false); } return items; } getMemos() is the crashed function. And another question, the error was also appeared on client thread. In my knowledge, PlayerLoggedInEvent is only fired on server. Am I right?
  3. @Animefan8888 Can you help me one more time? I tried to sync between (logical) server and client using PlayerLoggedInEvent and ServerConnectionFromClientEvent and both are failed with NullPointerException while loading basic classes(like BlockPos, etc.) I have literally no idea to fix this error. Is there any solutions? (or reference mods for more information...)
  4. Then can I change that?
  5. I've tried to draw 16x16 png image on ingameGui, but it was scaled incorrectly. When I change my offset values(3rd and 4th args) and it shows that the image is scaled wrong. But I can't figure out how to fix this even I've searched Lexica Botania's source code. Is there any way to fix this? Source Code(I'm on mobile, so the code will be not accurate and it's not formatted) mc.getTextureManager().bindTexture(new ResourceLocation(MODID, 'textures/icon/memo.png')); mc.ingameGui.drawTexturedModalRect(x, y, 0, 0, 16, 16);
  6. Thanks!
  7. Where should I call it? On Handler? And, what method should I pass?
  8. Oh, sorry. I just realized that mc.getIntegratedServer() only works on singleplayer mode. ;(
  9. Nevermind, I just solved the problem with accessing server world.
  10. Thanks. And then, if I should use packet, can I reuse my own IMessage implementation that I've used to send data to the server? Here's the code: public class PacketMemo implements IMessage { private BlockPos pos; private String text; private int color; public PacketMemo(){} public PacketMemo(BlockPos pos, String text, int color) { this.pos = pos; this.text = text; this.color = color; } @Override public void fromBytes(ByteBuf buf) { pos = BlockPos.fromLong(buf.readLong()); int textLength = buf.readInt(); char[] textArr = new char[textLength]; for (int i = 0; i < textLength; i++) { textArr[i] = buf.readChar(); } text = new String(textArr); color = buf.readInt(); } @Override public void toBytes(ByteBuf buf) { buf.writeLong(pos.toLong()); buf.writeInt(text.length()); for (int i = 0; i < text.length(); i++) { buf.writeChar(text.charAt(i)); } buf.writeInt(color); } public static class Handler implements IMessageHandler<PacketMemo, IMessage> { @Override public IMessage onMessage(PacketMemo message, MessageContext ctx) { FMLCommonHandler.instance().getWorldThread(ctx.netHandler).addScheduledTask(() -> handle(message, ctx)); return null; } public void handle(PacketMemo message, MessageContext ctx) { WSDMemo wsdMemo = WSDMemo.get(ctx.getServerHandler().player.getServerWorld()); wsdMemo.addOrEditMemo(message.pos, message.text, message.color); } } }
  11. How can I sync WorldSavedData between server and client(s)? I thought it was automatic, but the Forge doc says: So I'm figuring out how to sync it. Is there any way to do this easily, or should I send my NBTTagCompound to client using packets?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.