Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alt hotbar scrolling #3

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/cleanroommc/bogosorter/BogoSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void onPreInit(FMLPreInitializationEvent event) {
FMLCommonHandler.instance().bus().register(new ClientEventHandler());
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
MinecraftForge.EVENT_BUS.register(new ButtonHandler());
FMLCommonHandler.instance().bus().register(new HotbarSwap());
MinecraftForge.EVENT_BUS.register(new HotbarSwap());
}
}
Expand Down
21 changes: 10 additions & 11 deletions src/main/java/com/cleanroommc/bogosorter/common/HotbarSwap.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,10 @@ public class HotbarSwap {
private static boolean enabled = true;
private static boolean show;
private static int verticalIndex = 0;
protected static final RenderItem itemRenderer = RenderItem.getInstance();
private static final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
private static final TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();

public static boolean doCancelHotbarSwap() {
return show;
}

public static void setEnabled(boolean enabled) {
HotbarSwap.enabled = enabled;
}
Expand Down Expand Up @@ -62,7 +58,7 @@ public void render(RenderGameOverlayEvent.Post event) {
int x = m - 90 + player.inventory.currentItem * 20 + 2;
int y = event.resolution.getScaledHeight() - 16 - 3 - 70;
for (int i = 1; i < 4; i++) {
renderHotbarItem(x, y, event.partialTicks, player, player.inventory.getStackInSlot(player.inventory.currentItem + i * 9));
renderHotbarItem(Minecraft.getMinecraft().fontRenderer, Minecraft.getMinecraft().getTextureManager(), player.inventory.getStackInSlot(player.inventory.currentItem + i * 9),x,y, event.partialTicks);
y += 18;
}

Expand All @@ -78,7 +74,7 @@ public void onKeyInput(InputEvent.KeyInputEvent event) {
return;
}
if (show) {
if (!Keyboard.isKeyDown(Keyboard.KEY_LMENU) || !Keyboard.isKeyDown(Keyboard.KEY_RMENU)) {
if (!isAltKeyDown()) {
// swap items on server
if (verticalIndex != 0) {
int index = 4 - verticalIndex;
Expand All @@ -90,7 +86,7 @@ public void onKeyInput(InputEvent.KeyInputEvent event) {
verticalIndex = 0;
}
} else {
if (Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU)) {
if (isAltKeyDown()) {
show = true;
verticalIndex = 0;
}
Expand All @@ -114,10 +110,10 @@ public void onMouseInput(InputEvent.MouseInputEvent event) {
}
}

private static void renderHotbarItem(int x, int y, float partialTicks, EntityPlayer player, ItemStack stack) {
private static void renderHotbarItem(FontRenderer fontRenderer, TextureManager textureManager, ItemStack stack, int x, int y, float partialTicks) {
if (stack != null) {
RenderItem renderer = new RenderItem();
float f = (float) stack.animationsToGo - partialTicks;

if (f > 0.0F) {
GlStateManager.pushMatrix();
float f1 = 1.0F + f / 5.0F;
Expand All @@ -126,13 +122,16 @@ private static void renderHotbarItem(int x, int y, float partialTicks, EntityPla
GlStateManager.translate((float) (-(x + 8)), (float) (-(y + 12)), 0.0F);
}

itemRenderer.renderItemAndEffectIntoGUI(fontRenderer, textureManager,stack, x, y);
renderer.renderItemAndEffectIntoGUI(fontRenderer, textureManager,stack, x, y);

if (f > 0.0F) {
GlStateManager.popMatrix();
}

itemRenderer.renderItemOverlayIntoGUI(fontRenderer, textureManager, stack, x, y);
renderer.renderItemOverlayIntoGUI(fontRenderer, textureManager, stack, x, y);
}
}
public static boolean isAltKeyDown() {
return Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void decode(PacketBuffer buf) throws IOException {
public IPacket executeServer(NetHandlerPlayServer handler) {
ItemStack hotbarItem = handler.playerEntity.inventory.mainInventory[this.hotbarIndex];
ItemStack toSwapItem = handler.playerEntity.inventory.mainInventory[this.swapIndex];
if (hotbarItem.equals(toSwapItem)) return null;
if (hotbarItem == null || toSwapItem == null || hotbarItem.equals(toSwapItem)) return null;
handler.playerEntity.inventory.mainInventory[this.hotbarIndex] = toSwapItem;
handler.playerEntity.inventory.mainInventory[this.swapIndex] = hotbarItem;
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ public void sortBogo(SlotGroup slotGroup) {
ISlot slot = slots.get(i);
slot.bogo$putStack(items.get(i));
}
System.out.println(items);
System.out.println(slots);
}

public LinkedList<ItemSortContainer> gatherItems(SlotGroup slotGroup) {
Expand Down Expand Up @@ -281,7 +279,6 @@ public void randomizeItems(ISlot slot1) {
}

}
System.out.println(slots);
NetworkHandler.sendToServer(new CSlotSync(slots));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public enum Mixins {
Vanilla_BOTH(new Builder(" Vanilla").addTargetedMod(TargetedMod.VANILLA)
.setSide(Side.BOTH).setPhase(Phase.EARLY).addMixinClasses(
"minecraft.ContainerHorseInventoryMixin",
// "minecraft.MixinEntityPlayer",
// "minecraft.MixinEntityPlayer",
"minecraft.SlotMixin"
)),
Vanilla_CLIENT(new Builder(" Vanilla").addTargetedMod(TargetedMod.VANILLA)
.setSide(Side.CLIENT).setPhase(Phase.EARLY).addMixinClasses(
"minecraft.CreativeSlotMixin",
"minecraft.GuiContainerMixin",
"minecraft.GuiEditSignMixin"
// "minecraft.MinecraftMixin"
"minecraft.GuiContainerMixin",
"minecraft.GuiEditSignMixin",
"minecraft.MinecraftMixin"
)),

Avaritiaddons( new Builder(" Avaritiaddons").addTargetedMod(TargetedMod.AVARITIADDONS).setSide(Side.BOTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
@Mixin(Minecraft.class)
public class MinecraftMixin {

@Shadow
public EntityClientPlayerMP thePlayer;
@Shadow
public EntityClientPlayerMP thePlayer;

@Redirect(method = "runTick", at = @At(value = "INVOKE", target =
"Lnet/minecraft/entity/player/InventoryPlayer;changeCurrentItem(I)V"))
public void mouseInput(InventoryPlayer instance, int p_70453_1_) {
if (!HotbarSwap.doCancelHotbarSwap()) {thePlayer.inventory.changeCurrentItem(p_70453_1_);
}
}
@Redirect(method = "runTick", at = @At(value = "INVOKE", target =
"Lnet/minecraft/entity/player/InventoryPlayer;changeCurrentItem(I)V"))
public void mouseInput(InventoryPlayer instance, int p_70453_1_) {
if (!HotbarSwap.doCancelHotbarSwap()) {
thePlayer.inventory.changeCurrentItem(p_70453_1_);
}
}
}
Loading