Jump to content

Skyriis

Members
  • Posts

    176
  • Joined

  • Last visited

Everything posted by Skyriis

  1. Hi Guys, is there an easy way to add the player inventory to a non container screen? Or do i need to create a Container to add the player inventory? Thanks in advance
  2. I'll try that thank you!
  3. Hello i'm trying to get the source (player/mob/dispenser,...) of an effect which is/gets applied to another entity. Is there a way of doing this?
  4. Hi Guys, i'm trying to mixin into the KeyEntry class and add 2 Buttons there. In my test env everything works but as soon as i try it in a normal minecraft forge instance i'll get a MixinTransformerError which is caused by @Shadow field keybinding was not located in the target class net.minecraft.client.gui.widget.list.KeyBindingList$KeyEntry. No refMap loaded. Here is my mixin class: How can i fix that? Do i need to add an refMap.json somehow?
  5. Do you mean that pull request? https://github.com/MinecraftForge/MinecraftForge/pull/6858
  6. So i would have to manage the whole pose control using the player tick events if i want to prevent using mixin. Is that correct?
  7. I tried using the setForcePose method within the PlayerTickEvent (set the pose on pre tick event and remove the pose on post tick event) but somehow it's bugging between both poses. I guess the source of my problem is that Entity.getBoundingBoxForPose returns a bounding box for the default EntityType.PLAYER which is not what i need since i'm resizing the player inside of the EntityEvent.Size event. #Entity.class public EntitySize getDimensions(Pose p_213305_1_) { return this.type.getDimensions(); } protected AxisAlignedBB getBoundingBoxForPose(Pose p_213321_1_) { EntitySize entitysize = this.getDimensions(p_213321_1_); float f = entitysize.width / 2.0F; Vector3d vector3d = new Vector3d(this.getX() - (double)f, this.getY(), this.getZ() - (double)f); Vector3d vector3d1 = new Vector3d(this.getX() + (double)f, this.getY() + (double)entitysize.height, this.getZ() + (double)f); return new AxisAlignedBB(vector3d, vector3d1); } getDimensions(Pose) should return the set EntitySize from the EntityEvent.Size event to make it work without mixin. Or am i wrong with that?
  8. @Mixin(Entity.class) public abstract class MixinEntity { @Shadow public abstract EntityType<?> getType(); @Shadow public World level; @Shadow public abstract int getId(); @Inject(method = "getBoundingBoxForPose", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/entity/Entity;getDimensions(Lnet/minecraft/entity/Pose;)Lnet/minecraft/entity/EntitySize;"), cancellable = true) private void getBoundingBoxForPose(Pose pose, CallbackInfoReturnable<AxisAlignedBB> cir) { if (!this.getType().equals(EntityType.PLAYER)) return; Entity entity = level.getEntity(getId()); if (entity == null) return; entity.getCapability(CapabilityHelper.RACE_CAPABILITY).ifPresent(iRaceProvider -> { final AxisAlignedBB axisAlignedBB = iRaceProvider.getRace().getPlayerBoundingBox(entity, pose); cir.setReturnValue(axisAlignedBB); }); } } i've used mixin to fix my problem but since i have no clue what i'm doing here i would be grateful for alternatives!
  9. Hi, i wrote a mod which can grow and shrink the player but if the player is shrinked they crawl if they are inside a 1 block gap or if they jump inside a 2 block gap. How can i prevent them from doing that? I tried using the EntityEvent.Size and check if the event.getPose is Swimming (since this is the pose the player is using while crawling) but the entity isn't inside water. But it doesn't seems to work. Any ideas?
  10. I tried new Thread(() -> { while (ClientModLoader.isLoading()) { try { TimeUnit.SECONDS.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } } Minecraft.getInstance().enqueue(() -> SyncHandler.applyKeybindings()); }).start(); and it would "work" but since GameSettings is not threadsafe it would be a bad idea to use this correct?
  11. I could also start a new Thread at FMLClientSetupEvent which could wait for the loadup and instandly apply the Keybindings but i'm not sure if that would be a good way since the new Thread would have to check ClientModLoader.isLoading until it's false...
  12. The loaded Keybindings only should be applied to the running instance at startup (or exactly after startup). The Goal is to make a Mod which sets your favorite keybinds on the first load and sync changed (favorite) keybinds to other instances so you don't have to set them manually anymore.
  13. The GameSettings.setKeyBindingCode() Method should call the saveOptions() Method which should save the Keybindings to the options.txt file. But the Keybindings only apply if there is no options.txt before startup. If the options.txt has been generated, the loaded Keybindings don't apply to the started instance anymore. Even if i load the options.txt again using the loadOptions() Method, the Keybinds won't be there. Edit: i guess the if (net.minecraftforge.fml.client.ClientModLoader.isLoading()) return; part inside of the saveOptions() chould be the issue since i'm calling it at the FMLClientSetupEvent. Is there a better Event i chould use to apply the Keybindings?
  14. I'm trying to load already changed keybindings from other Profiles to the current instance so the keybindings are already set if you start playing. This only applies to keybindings which where marked in the original Profile and should sync to other Profiles.
  15. Hi Guys, i'm trying to change the input key of a keybinding if the keybinding is contained by a HashMap (which also contains the new input key). Here is what i'm calling at the FMLClientSetupEvent. KeyBinding[] keyBindings = Minecraft.getInstance().gameSettings.keyBindings.clone(); for (KeyBinding keyBinding : keyBindings) { if (SyncedKeyBindings.containsKey(keyBinding.getKeyDescription())) { KeyData data = SyncedKeyBindings.get(keyBinding.getKeyDescription()); keyBinding.setKeyModifierAndCode(data.getModifier(), data.getValue()); final GameSettings gameSettings = Minecraft.getInstance().gameSettings; if (data.getValue().toString().contains("mouse")) { gameSettings.setKeyBindingCode(keyBinding, InputMappings.Type.MOUSE.getOrMakeInput(data.getValue().getKeyCode())); } else { gameSettings.setKeyBindingCode(keyBinding, InputMappings.getInputByName(data.getValue().toString())); } LOGGER.debug("Changed " + data.getIdentidier() + " to " + data.getModifier().toString() + " + " + data.getValue().toString()); } } KeyBinding.resetKeyBindingArrayAndHash(); For some reason the new input won't be appled to the keybinding. Is the FMLClientSetupEvent to early to change the input key? Or am i missing something?
  16. I more or less found the problem. There is a event listender on the left side of the screen which was blocking the button. I just moved the button to another place because i could not find the listender. Now everything works like it should.
  17. Now the added Button (btnSyncToCloud) isn't clickable but hoverable. All other buttons are clickable and work how the should. Changed KeyBindingListReplacement.KeyEntry.class @OnlyIn(Dist.CLIENT) public class KeyEntryReplacement extends KeyBindingList.Entry { /** * The keybinding specified for this KeyEntry */ private final KeyBinding keybinding; /** * The localized key description for this KeyEntry */ private final ITextComponent keyDesc; private final Button btnChangeKeyBinding; private final Button btnReset; private final IconButton btnSyncToCloud; private KeyEntryReplacement(final KeyBinding keyBinding, final ITextComponent description) { this.keybinding = keyBinding; this.keyDesc = description; this.btnChangeKeyBinding = new Button(0, 0, 75 + 20, 20, description, (p_214386_2_) -> KeyBindingListReplacement.this.controlsScreen.buttonId = keyBinding) { protected IFormattableTextComponent getNarrationMessage() { return keyBinding.isInvalid() ? new TranslationTextComponent("narrator.controls.unbound", description) : new TranslationTextComponent("narrator.controls.bound", description, super.getNarrationMessage()); } }; this.btnReset = new Button(0, 0, 50, 20, new TranslationTextComponent("controls.reset"), (p_214387_2_) -> { keybinding.setToDefault(); KeyBindingListReplacement.this.minecraft.gameSettings.setKeyBindingCode(keyBinding, keyBinding.getDefault()); KeyBinding.resetKeyBindingArrayAndHash(); }) { protected IFormattableTextComponent getNarrationMessage() { return new TranslationTextComponent("narrator.controls.reset", description); } }; this.btnSyncToCloud = new IconButton("cloud", (button) -> SyncHandler.addToSyncList(this.keybinding)) { @Override protected IFormattableTextComponent getNarrationMessage() { return new TranslationTextComponent("belovedkeybindings.buttons.upload_to_cloud", description); } }; } @Override public void render(MatrixStack matrixStack, int p_230432_2_, int renderPosY, int renderPosX, int p_230432_5_, int p_230432_6_, int mouseX, int mouseY, boolean p_230432_9_, float particalTicks) {...} public List<? extends IGuiEventListener> getEventListeners() { return ImmutableList.of(this.btnChangeKeyBinding, this.btnReset, this.btnSyncToCloud); } @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { return this.btnChangeKeyBinding.mouseClicked(mouseX, mouseY, button) || this.btnReset.mouseClicked(mouseX, mouseY, button) || this.btnSyncToCloud.mouseClicked(mouseX, mouseY, button); } @Override public boolean mouseReleased(double mouseX, double mouseY, int button) { return this.btnChangeKeyBinding.mouseReleased(mouseX, mouseY, button) || this.btnReset.mouseReleased(mouseX, mouseY, button) || this.btnSyncToCloud.mouseReleased(mouseX, mouseY, button); } } IconButton.class @OnlyIn(Dist.CLIENT) public class IconButton extends ImageButton { private final ResourceLocation resourceLocation; private final int yOffset = 128; public IconButton(String iconName, IPressable onPressIn) { super(0, 0, 20, 20, 0, 0, 128, new ResourceLocation(BelovedKeybindings.MODID, "textures/icons/" + iconName + ".png"), onPressIn); this.resourceLocation = new ResourceLocation(BelovedKeybindings.MODID, "textures/icons/" + iconName + ".png"); } @Override public void renderButton(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { Minecraft minecraft = Minecraft.getInstance(); minecraft.getTextureManager().bindTexture(this.resourceLocation); int i = 0; if (this.isMouseOver(mouseX, mouseY)) { i += yOffset; } RenderSystem.disableDepthTest(); blit(matrixStack, this.x, this.y, 16, 16, 0, i, 128, 128, 256, 256); RenderSystem.enableDepthTest(); if (this.isMouseOver(mouseX, mouseY)) { this.renderToolTip(matrixStack, mouseX, mouseY); } } @Override public void renderToolTip(MatrixStack matrixStack, int mouseX, int mouseY) { super.renderToolTip(matrixStack, mouseX, mouseY); Minecraft.getInstance().fontRenderer.drawStringWithShadow(matrixStack, getNarrationMessage().getString(), mouseX + 8, mouseY, Color.WHITE.getRGB()); } } Any ideas how to fix that?
  18. I'll work on that Thanks. I'll remove those lines.
  19. That worked. Here is my solution @SubscribeEvent public static void onOpenGui(final GuiScreenEvent.InitGuiEvent.Post event) { if (!(event.getGui() instanceof ControlsScreen)) return; final ControlsScreen controlsScreen = (ControlsScreen) event.getGui(); final KeyBindingList replacement = new KeyBindingListReplacement(controlsScreen, event.getGui().getMinecraft()); final KeyBindingList old = ObfuscationReflectionHelper.getPrivateValue(ControlsScreen.class, controlsScreen, "field_146494_r"); controlsScreen.getEventListeners().remove(old); ObfuscationReflectionHelper.setPrivateValue(ControlsScreen.class, controlsScreen, replacement, "field_146494_r"); try { Method addChildMethod = ObfuscationReflectionHelper.findMethod(Screen.class, "func_230481_d_", IGuiEventListener.class); addChildMethod.setAccessible(true); addChildMethod.invoke(controlsScreen, replacement); addChildMethod.setAccessible(false); } catch (IllegalAccessException | InvocationTargetException e) { e.printStackTrace(); } }
  20. Event Handler private static KeyBindingListReplacement replacement; @SubscribeEvent public static void onOpenGui(final GuiScreenEvent.InitGuiEvent.Post event) { if (!(event.getGui() instanceof ControlsScreen)) return; ControlsScreen controlsScreen = (ControlsScreen) event.getGui(); replacement = new KeyBindingListReplacement(controlsScreen, event.getGui().getMinecraft()); ObfuscationReflectionHelper.setPrivateValue(ControlsScreen.class, controlsScreen, replacement, "field_146494_r"); } @SubscribeEvent public static void onScroll(final GuiScreenEvent.MouseScrollEvent.Pre event) { if (!(event.getGui() instanceof ControlsScreen)) return; replacement.mouseScrolled(event.getMouseX(), event.getMouseY(), event.getScrollDelta()); } Replacement: @OnlyIn(Dist.CLIENT) public class KeyBindingListReplacement extends KeyBindingList { private final ControlsScreen controlsScreen; private int maxListLabelWidth; public KeyBindingListReplacement(ControlsScreen controls, Minecraft mcIn) { super(controls, mcIn); this.controlsScreen = controls; this.clearEntries(); KeyBinding[] akeybinding = ArrayUtils.clone(mcIn.gameSettings.keyBindings); Arrays.sort(akeybinding); String lastCategory = null; for (KeyBinding keybinding : akeybinding) { String keyCategory = keybinding.getKeyCategory(); if (!keyCategory.equals(lastCategory)) { lastCategory = keyCategory; this.addEntry(new KeyBindingList.CategoryEntry(new TranslationTextComponent(keyCategory))); } ITextComponent itextcomponent = new TranslationTextComponent(keybinding.getKeyDescription()); int i = mcIn.fontRenderer.getStringPropertyWidth(itextcomponent); if (i > this.maxListLabelWidth) { this.maxListLabelWidth = i; } this.addEntry(new KeyEntry(keybinding, itextcomponent)); } }
  21. I was able to replace the keybindinglist with my own list but now the list isn't scollable anymore. I fixed that by using the GuiScreenEvent.MouseScrollEvent. Is there a better way of doing that?
  22. I tried the InitGuiEvent but the KeyBindingList is no Widget and no Screen so i can't modify it there. Can I? Is there a way to modify the KeyBindingList?
  23. Hi Guys, i'm trying to add a Button on the left of each keybinding in the Controls Screen. Is there a way to do that without replacing the whole Screen?
×
×
  • Create New...

Important Information

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