Jump to content

cinsiian

Members
  • Posts

    110
  • Joined

  • Last visited

Everything posted by cinsiian

  1. So the packet will be(Server-ToClient): public class ManaPacket { public int mana; public ManaPacket() {} public ManaPacket(int mana) { this.mana = mana; } public static void writeIn(ManaPacket packet, PacketBuffer buffer) { buffer.writeInt(packet.mana); } public static ManaPacket readIn(PacketBuffer buffer) { return new ManaPacket(buffer.readInt()); } public static class PacketHandler { public static void run(final ManaPacket packet, Supplier<NetworkEvent.Context> context) { context.get().enqueueWork(() -> { int i = context.get().getSender().getCapability(ManaProvider.MANA, null).orElseThrow(null).get(); packet.mana = i; }); } } }
  2. What handler? The handler of the actual packet or the handler of the network?
  3. ok but how do i actually set the client mana? In the packet's Handler? https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/network/ToClientMessageOreParticles.java#L54 Like here? And how can I get the serverplayer? Do I have to save it in the packet as well?
  4. Can someone explain how to use the network system? I tried to get it work with the documentation as a reference without success.
  5. Basically if its the same player, it will take the data from the server(ManaUtils methods) and update them to the client player(Minecraft.getInstance().player). I tried to do that...
  6. So basically what I did is this and seems that its working. public static void updateMana(PlayerEntity player) { IMana oldMana = ManaUtils.getMana(Minecraft.getInstance().player); IMana newMana = ManaUtils.getMana(player); if(oldMana != null && newMana != null) { oldMana.set(newMana.get()); } }
  7. Ok, it did work but i have few issues setting up the capability adding/setting the value. https://github.com/cinsiian/mod/blob/master/java/cinsiian/urtima/util/ManaUtils.java The hud displays the correct amount of mana but when I try consuming it for some reason it return that the player does not have the correct mana amount
  8. there is Player.isSwimming but I also need if the player is underwater even without swimming
  9. Thank you guys, now textures work perfectly but I have few last things to ask. 1) How can I see if the air bubble bar is rendered(so i can move the mana bar up so it does not contrast)? 2) What is the correct way to get/set the capability?, I used: player.getCapability(ManaProvider.MANA, null).orElseThrow(null).get() player.getCapability(ManaProvider.MANA, null).orElseThrow(null).set() It's really buggy, sometimes it doesnt even do anything
  10. What are the RenderGameOverlayEvent.Pre and RenderGameOverlayEvent.Post ?
  11. Ok so I managed to get the event work but the texture is not rendering correctly: public final ResourceLocation TEXTURE = new ResourceLocation(Reference.MODID, "textures/gui/mana_hud.png"); @SubscribeEvent public void renderOverlay(RenderGameOverlayEvent event) { if(event.getType() == ElementType.AIR) { Minecraft mc = Minecraft.getInstance(); int x = event.getWindow().getScaledWidth() / 2 + 10; int y = event.getWindow().getScaledHeight() - 48; if(!(mc.player.isSpectator() || mc.player.isCreative())) { mc.getTextureManager().bindTexture(TEXTURE); drawBackground(x, y); } } } private void drawBackground(int x, int y) { drawTexturedModalRect(x, y, 0, 0, 89, 9); } private void drawTexturedModalRect(int x, int y, int textureX, int textureY, int width, int height) { Minecraft mc = Minecraft.getInstance(); mc.ingameGUI.blit(x, y, textureX, textureY, width, height); } The texture: https://ibb.co/ct9XNRy In-game: https://ibb.co/PzyTqkP
  12. Ok, I dont get the crash anymore when I join. Everything seems working right now, I returned LazyOptional.of(() -> INSTANCE).cast(); https://github.com/cinsiian/mod/tree/master/java/cinsiian/urtima/common/capability/mana Thats the full package related to mana, everything should be ok. Now I will start working on the Bar in the RenderGameOverlayEvent. Is RenderGameOverlayEvent executed every tick? I will check every tick: if the mana is 20 I render a thing, if its 19 render another thing ecc...
  13. @CapabilityInject(IMana.class) public static final Capability<IMana> MANA = null; public IMana INSTANCE = MANA.getDefaultInstance(); @SuppressWarnings("unchecked") public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) { return (LazyOptional<T>) INSTANCE; } How can I return an actual instance of LazyOptional?
  14. to return in the getCapability() can i just make a new LazyOptional?
  15. What LazyOptional ?? like the default one this.getCompatibility() ?
  16. You can't do this either don't know if I'm looking at outdated code or not. Isn't that the thing I should return?
  17. It's the ManaProvider class: https://github.com/cinsiian/mod
×
×
  • Create New...

Important Information

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