Jump to content

matthew123

Members
  • Posts

    132
  • Joined

  • Last visited

Everything posted by matthew123

  1. private static int executeCommand(CommandContext<CommandSource> commandContext) throws CommandSyntaxException { Entity entity = commandContext.getSource().getEntity(); TranslationTextComponent finalText = new TranslationTextComponent("chat.type.announcement", commandContext.getSource().getDisplayName(), new StringTextComponent("ok")); commandContext.getSource().getServer().getPlayerList().broadcastMessage(finalText, ChatType.CHAT, entity.getUUID()); ServerPlayerEntity playerEntity = commandContext.getSource().getPlayerOrException(); playerEntity.getCapability(AbilityCapabilityProvider.Ability_CAPABILITY).ifPresent(AbilityData -> { AbilityData.addAbility(NatureTypes.A, new AbilityData(NatureTypes.A, "mymod:a", 0, 0, 1)); AbilityData.addAbility(NatureTypes.A, new AbilityData(NatureTypes.A, "mymod:b", 0, 0, 1)); AbilityData.addAbility(NatureTypes.B, new AbilityData(NatureTypes.B, "mymod:c", 0, 0, 1)); AbilityData.addAbility(NatureTypes.B, new AbilityData(NatureTypes.B, "mymod:d", 0, 0, 1)); AbilityData.addAbility(NatureTypes.D, new AbilityData(NatureTypes.D, "mymod:e", 0, 0, 1)); AbilityData.addAbility(NatureTypes.E, new AbilityData(NatureTypes.E, "mymod:f", 0, 0, 1)); ModNetwork.sendTo(new ServerSyncAbilityMessage(AbilityData), playerEntity); ModNetwork.sendTo(new ServerSyncPowerMessage(42, 42), playerEntity); }); return 1; }
  2. I see. Checking if the screen is null works. I assume the Screen class is used for machine GUIs and game GUIs.
  3. That works, but I need to check if the player is InGame. That is because the clicks can still register if the player is in e.g the options screen. Is there a screen class used for the game itself?
  4. I must mention that I am using 1.16.5
  5. Could not find the class, but i found a method on screen called isPauseScreen but it does not work. Minecraft.getInstance().screen == null || Minecraft.getInstance().screen.isPauseScreen() is always true.
  6. I am listening for MouseInputEvents, and I would like to know how I can find out if the player is in-game or in the pause menu.
  7. To clarify, I added logging to the storage class (where writeNBT and readNBT are being called).
  8. Of course. But the logging i added to them indicates that default values are being written.
  9. The code above is used to synchronize the capability on the server. The correct values are printed out by the logger, but when I check the values with NBTExplorer, they are the default ones. Thus, when re-joining the singleplayer world, the capability has the default values.
  10. I am actually changing it in many places. My interface accesses the capability on the player to draw it. This is where it gets updated on the server: public static void handlePacket(ClientSyncOverlayMessage message, Supplier<NetworkEvent.Context> ctx) { LogManager.getLogger().info("Got sync overlay message! Selected: " + message.getSelectedTechnique().getId() + " nature: " + message.getSelectedTechnique().getNature()); ServerPlayerEntity playerEntity = ctx.get().getSender(); playerEntity.getCapability(TechniqueCapabilityProvider.Technique_CAPABILITY).ifPresent(TechniqueCapability -> { TechniqueCapability.setSelectedTechniqueFor(message.getSelectedTechnique().getNature(), message.getSelectedTechnique()); LOGGER.info("Updated selected Technique to " + message.getSelectedTechnique().getId() + ", power level: " + message.getSelectedTechnique().getPower()); LOGGER.info("PW after update: " + TechniqueCapability.getSelectedTechniqueFor(TechniqueCapability.getSelectedNatureOrDefault()).getPower()); }); } P.S i renamed the capability to TechniqueCapability in this example.
  11. This is my capability provider. public class MyCapabilityProvider implements ICapabilitySerializable<INBT> { @CapabilityInject(IMyCapability.class) public static Capability<IMyCapability> My_CAPABILITY = null; private final LazyOptional<IMyCapability> lazyOptional = LazyOptional.of(MyCapability::new); @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction side) { if (capability == My_CAPABILITY) { return lazyOptional.cast(); } return LazyOptional.empty(); } @Override public INBT serializeNBT() { return My_CAPABILITY.getStorage().writeNBT(My_CAPABILITY, lazyOptional.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null); } @Override public void deserializeNBT(INBT nbt) { My_CAPABILITY.getStorage().readNBT(My_CAPABILITY, lazyOptional.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null, nbt); } } The issue is that the values written to the disk are the default values for my capability data. I added some logging to the storage class, and this confirms it. Why is that happening?
  12. To do that, it would mean i'd have to change the Dist to Client. Wouldn't that break the event on dedicated servers?
  13. I see. So the server used by singleplayer does not qualify as DedicatedServer. How would I sync the capability, then?
  14. Singleplayer.
  15. I wish to use this event to send capability data to clients when they join. For some reason, my event is not firing.
  16. My input system uses a hotkey + scrolling. How may I prevent the inventory hotbar from scrolling [while my key is being pressed]?
  17. By collections, I mean maps of lists and such. Syncing will be a pain. If there is no immediate issue other than a little performance loss, I will just keep it like that until i do a refactoring and cleanup session on the code.
  18. I have quite a complex capability, with some collections. I thought that it would be too troublesome to create network messages for every operation I make, so I instead used the storage class to serialize the whole capability class and send it to the client. I then added some methods on the capability class to replace the references in the fields with the ones from the deserialized class. The performance loss is insignificant, as I will rarely be using it. Is there anything I should be concerned about?
  19. I am ashamed -frowns- Guess I can't call myself a programmer anymore.
  20. I did not fully understand capabilities (specifically the capability provider). I am now facing an issue I believe has to do with an instance of my capability class lingering. I arrived at this conclusion by logging inside the capability class's constructor. Upon joining my single player world, the log indicates that the class was instanced. Upon leaving, then joining again, the message no longer appears. I believe this has to do with the static LazyOptional field doohickey inside this class: public class CapabilityProvider implements ICapabilitySerializable<INBT> { @CapabilityInject(ITheCapability.class) public static Capability<ITheCapability> CAPABILITY = null; private static final LazyOptional<ITheCapability> lazyOptional = LazyOptional.of(TheCapability::new); @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> capability, @Nullable Direction side) { // don't use the one line if statement. if (capability == CAPABILITY) { return lazyOptional.cast(); } return LazyOptional.empty(); } @Override public INBT serializeNBT() { return CAPABILITY.getStorage().writeNBT(CAPABILITY, lazyOptional.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null); } @Override public void deserializeNBT(INBT nbt) { CAPABILITY.getStorage().readNBT(CAPABILITY, lazyOptional.orElseThrow(() -> new IllegalArgumentException("LazyOptional must not be empty!")), null, nbt); } } That static field obviously persists and essentially turns my class into a singleton, which is not what I want. Can anyone explain the usage of LazyOptional and how to fix my implementation?
  21. I was not. It now works. But that still does not solve the fundamental issue. Knowing the cause of the issue and fixing it myself will always be superior to getting help fixing it.
  22. Without an even rudimentary understanding of the code, I cannot figure out why this does not work. textureManager.bind(new ResourceLocation("mod:textures/overlay/bar.png")); // ?? RenderSystem.enableBlend(); // extract image from bound texture (from x 0, y 0 with width 128, height 10) and draw it to screen starting from x 100, y 100 mc.gui.blit(matrix, 100, 100, 0, 0, 128, 10); // ?? RenderSystem.disableBlend();
  23. Do you know of any document explaining the parameters and what the methods do? I am very new to graphics programming, and understanding the code with obfuscated names is quite hard. I have been successful in copying and modifying vanilla code, but using it whilst not understanding it is unacceptable for me.
  24. Greetings! The model was scaled correctly. This is how it should look like in-game:
  25. @SubscribeEvent public void renderGameOverlay(RenderGameOverlayEvent.Post event) { if(event.getType() != RenderGameOverlayEvent.ElementType.ALL) { return; } LOGGER.info("render!"); } This seems to work. Thank you!
×
×
  • Create New...

Important Information

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