• Recently Browsing

    No registered users viewing this page.

  • Posts

    • That's right. That me briefly explain the situation here: You want to sync the mental value of the player on server to client, and you had sent a packet that contains the value, in order to use it and render images on the screen. To get the value when rendering the screen, you are going to access the capability of the client player, therefore you need to assign the value from the packet to the client player's capability.   So: (make sure you do this on client using dist executor!) MyCap cap = Minecraft.getInstance().player.getCapability(....); cap.setMental(valuefromserver);   where cap is the client player' capability, and valuefromserver is the mental value got from the server player's capability that you want to assign(Sync) to the client.   Then you can use the same way above to access the value stored in the capability of the client player to render the images.   Also make sure you only send the packet when there's data change.
    • 09:24:32.702 Prepared asset index 09:24:32.729 Have 2154 total files to check or download 09:24:32.733 Waiting for 2154 futures 09:24:33.582 Nothing to download! 09:24:33.582 Extracting 8 files! 09:24:33.777 Installing versions!
    • public static void handle(PlayerMentalCapabilityMessage msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { }); ctx.get().setPacketHandled(true); } Is this all right? public static void handle(MyMessage msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { // Work that needs to be threadsafe (most work) EntityPlayerMP sender = ctx.get().getSender(); // the client that sent this packet // do stuff }); ctx.get().setPacketHandled(true); } This is what the forge docs say, but if I'm right, EntityPlayerMP sender = ctx.get (). GetSender (); is for sending from client to server. I don't know how to send from server to client instead. public class MentalOverlayHander { public static final ResourceLocation MENTALICON = new ResourceLocation("depressionmod:textures/gui/overlay.png"); private final Minecraft mc = Minecraft.getInstance(); public int _currentMental; @SubscribeEvent public void onPreRenderOverlay(RenderGameOverlayEvent.Post event) { if (event.getType() == ElementType.ALL && mc.playerController.gameIsSurvivalOrAdventure()) { int scaledWidth = this.mc.getMainWindow().getScaledWidth(); int scaledHeight = this.mc.getMainWindow().getScaledHeight(); int left_height = ForgeIngameGui.left_height; int left = scaledWidth / 2 - 91; int top = scaledHeight - left_height; int level = _currentMental; RenderSystem.enableBlend(); RenderSystem.enableAlphaTest(); RenderSystem.color4f(1F, 1F, 1F, 1F); mc.getTextureManager().bindTexture(MENTALICON); for (int i = 0; i < 10; ++i) { //iが10未満のとき繰り返す。iは繰り返しごとに1増える。 int idx = i * 2 + 1; if (idx < level) { //iがMPより小さいとき普通の薬を描画。 //mc.getTextureManager().bindTexture(MENTALICON); mc.ingameGUI.blit(left, top, 0, 0, 9, 9); } else if (idx == level) { //iがMPと同じとき半分の薬を描画。 //mc.getTextureManager().bindTexture(MENTALICON); mc.ingameGUI.blit(left, top, 9, 0, 9, 9); } else if (idx > level) { //iがMPより大きいとき黒の薬を描画。 //mc.getTextureManager().bindTexture(MENTALICON); mc.ingameGUI.blit(left, top, 18, 0, 9, 9); } left += 8; //アイコンを描画する位置を右に一つ分ずらす } RenderSystem.disableBlend(); mc.getTextureManager().bindTexture(AbstractGui.GUI_ICONS_LOCATION); } } } I want to put the currentMental value of PlayerMentalCapabilityMessage in _currentMental of MentalOverlayHander.
    • Handle is called when the client has received the packet, so there should be where you sync the data (what you've done in the previous post is correct), which you should get the client player and its capability to sync in here. Also:  You can get the context from the supplier (given in the second parameter of handle(...), then call Context#setPacketHandled)
    • public class PlayerMentalCapabilityMessage { ClientPlayerEntity player = Minecraft.getInstance().player; LazyOptional<PlayerMentalInterface> playermentalinterface = player.getCapability(PlayerMentalCapabilityRegistry.PLAYER_MENTAL_CAPABILITY); int currentMental = ((PlayerMentalInterface) playermentalinterface).getMental(); public PlayerMentalCapabilityMessage(int currentMental) { this.currentMental = currentMental; } public static void encode(PlayerMentalCapabilityMessage message, PacketBuffer buf) { buf.writeInt(message.currentMental); } public static PlayerMentalCapabilityMessage decode(PacketBuffer buf) { int currentMental = buf.readInt(); return new PlayerMentalCapabilityMessage(currentMental); } public static void handle(PlayerMentalCapabilityMessage msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { }); } } Is it like this? I'm still not sure about Context.setPacketHandled () so please tell me more.
  • Topics

  • Who's Online (See full list)