-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleared up and finished Hotbar Slot Locking
- Loading branch information
Tripp1e
committed
Feb 7, 2024
1 parent
b75b3a3
commit fdc4996
Showing
15 changed files
with
162 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/tripp1e/isleshelper/features/general/HotbarSlotLock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.tripp1e.isleshelper.features.general; | ||
|
||
import com.tripp1e.isleshelper.config.ConfigManager; | ||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.minecraft.client.option.KeyBinding; | ||
import org.lwjgl.glfw.GLFW; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.List; | ||
|
||
//From https://github.com/SkyblockerMod/Skyblocker/blob/master/src/main/java/de/hysky/skyblocker/skyblock/item/HotbarSlotLock.java | ||
public class HotbarSlotLock { | ||
public static KeyBinding hotbarSlotLock; | ||
public static void init() { | ||
hotbarSlotLock = KeyBindingHelper.registerKeyBinding( new KeyBinding( | ||
"key.hotbarSlotLock", | ||
GLFW.GLFW_KEY_H, | ||
"key.categories.isleshelper" | ||
)); | ||
} | ||
|
||
public static boolean isLocked(int slot) { | ||
return ConfigManager.get().general.lockedSlots.contains(slot); | ||
} | ||
|
||
public static void handleDropSelectedItem(int slot, CallbackInfoReturnable<Boolean> cir) { | ||
if (isLocked(slot)) cir.setReturnValue(false); | ||
} | ||
|
||
public static void handleInputEvents(ClientPlayerEntity player) { | ||
while (hotbarSlotLock.wasPressed()) { | ||
List<Integer> lockedSlots = ConfigManager.get().general.lockedSlots; | ||
int selected = player.getInventory().selectedSlot; | ||
if (!isLocked(player.getInventory().selectedSlot)) lockedSlots.add(selected); | ||
else lockedSlots.remove(Integer.valueOf(selected)); | ||
ConfigManager.save(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/tripp1e/isleshelper/mixin/ClientPlayerEntityMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.tripp1e.isleshelper.mixin; | ||
|
||
import com.mojang.authlib.GameProfile; | ||
import com.tripp1e.isleshelper.features.general.HotbarSlotLock; | ||
import net.minecraft.client.network.AbstractClientPlayerEntity; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import net.minecraft.client.world.ClientWorld; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
// From https://github.com/SkyblockerMod/Skyblocker/blob/master/src/main/java/de/hysky/skyblocker/mixin/ClientPlayerEntityMixin.java | ||
@Mixin(ClientPlayerEntity.class) | ||
public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity { | ||
|
||
public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) {super(world, profile);} | ||
@Inject(method = "dropSelectedItem", at = @At("HEAD"), cancellable = true) | ||
public void skyblockisles$dropSelectedItem(CallbackInfoReturnable<Boolean> cir) { | ||
HotbarSlotLock.handleDropSelectedItem(this.getInventory().selectedSlot, cir); | ||
} | ||
|
||
} |
22 changes: 0 additions & 22 deletions
22
src/main/java/com/tripp1e/isleshelper/mixin/HandledScreenAccessor.java
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
src/main/java/com/tripp1e/isleshelper/mixin/InGameHudMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.tripp1e.isleshelper.mixin; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import com.tripp1e.isleshelper.IslesHelperClient; | ||
import com.tripp1e.isleshelper.features.general.HotbarSlotLock; | ||
import net.fabricmc.api.EnvType; | ||
import net.fabricmc.api.Environment; | ||
import net.minecraft.client.gui.DrawContext; | ||
import net.minecraft.client.gui.hud.InGameHud; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.Identifier; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.function.Supplier; | ||
|
||
// From https://github.com/SkyblockerMod/Skyblocker/blob/master/src/main/java/de/hysky/skyblocker/mixin/InGameHudMixin.java | ||
@Environment(EnvType.CLIENT) | ||
@Mixin(InGameHud.class) | ||
public abstract class InGameHudMixin { | ||
@Unique | ||
private static final Supplier<Identifier> SLOT_LOCK_ICON = () -> new Identifier(IslesHelperClient.MOD_ID, "textures/slotlock.png"); | ||
|
||
@Inject(method = "renderHotbar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/hud/InGameHud;renderHotbarItem(Lnet/minecraft/client/gui/DrawContext;IIFLnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/item/ItemStack;I)V", ordinal = 0)) | ||
public void skyblocker$renderHotbarItemLockOrRarityBg(float tickDelta, DrawContext context, CallbackInfo ci, @Local(ordinal = 4, name = "m") int index, @Local(ordinal = 5, name = "n") int x, @Local(ordinal = 6, name = "o") int y, @Local PlayerEntity player) { | ||
if (HotbarSlotLock.isLocked(index)) { | ||
RenderSystem.enableBlend(); | ||
context.drawTexture(SLOT_LOCK_ICON.get(), x, y, 0, 0, 16, 16, 16, 16); | ||
RenderSystem.disableBlend(); | ||
} | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/tripp1e/isleshelper/mixin/MinecraftClientMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.tripp1e.isleshelper.mixin; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import com.tripp1e.isleshelper.features.general.HotbarSlotLock; | ||
|
||
|
||
// From https://github.com/SkyblockerMod/Skyblocker/blob/master/src/main/java/de/hysky/skyblocker/mixin/MinecraftClientMixin.java | ||
@Mixin(MinecraftClient.class) | ||
public abstract class MinecraftClientMixin { | ||
|
||
@Shadow | ||
@Nullable | ||
public ClientPlayerEntity player; | ||
|
||
@Inject(method = "handleInputEvents", at = @At("HEAD")) | ||
public void skyblocker$handleInputEvents(CallbackInfo ci) { | ||
HotbarSlotLock.handleInputEvents(player); | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters