diff --git a/src/main/java/com/cleanroommc/bogosorter/BogoSorter.java b/src/main/java/com/cleanroommc/bogosorter/BogoSorter.java index 75bdce77..525222f5 100644 --- a/src/main/java/com/cleanroommc/bogosorter/BogoSorter.java +++ b/src/main/java/com/cleanroommc/bogosorter/BogoSorter.java @@ -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()); } } diff --git a/src/main/java/com/cleanroommc/bogosorter/common/HotbarSwap.java b/src/main/java/com/cleanroommc/bogosorter/common/HotbarSwap.java index cb5cffab..e414880f 100644 --- a/src/main/java/com/cleanroommc/bogosorter/common/HotbarSwap.java +++ b/src/main/java/com/cleanroommc/bogosorter/common/HotbarSwap.java @@ -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; } @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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); + } } diff --git a/src/main/java/com/cleanroommc/bogosorter/common/network/CHotbarSwap.java b/src/main/java/com/cleanroommc/bogosorter/common/network/CHotbarSwap.java index 57568b2e..353c94e4 100644 --- a/src/main/java/com/cleanroommc/bogosorter/common/network/CHotbarSwap.java +++ b/src/main/java/com/cleanroommc/bogosorter/common/network/CHotbarSwap.java @@ -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; diff --git a/src/main/java/com/cleanroommc/bogosorter/common/sort/SortHandler.java b/src/main/java/com/cleanroommc/bogosorter/common/sort/SortHandler.java index d69e3171..ee960b7f 100644 --- a/src/main/java/com/cleanroommc/bogosorter/common/sort/SortHandler.java +++ b/src/main/java/com/cleanroommc/bogosorter/common/sort/SortHandler.java @@ -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 gatherItems(SlotGroup slotGroup) { @@ -281,7 +279,6 @@ public void randomizeItems(ISlot slot1) { } } - System.out.println(slots); NetworkHandler.sendToServer(new CSlotSync(slots)); } } diff --git a/src/main/java/com/cleanroommc/bogosorter/mixinplugin/Mixins.java b/src/main/java/com/cleanroommc/bogosorter/mixinplugin/Mixins.java index 72d2b41f..208fba50 100644 --- a/src/main/java/com/cleanroommc/bogosorter/mixinplugin/Mixins.java +++ b/src/main/java/com/cleanroommc/bogosorter/mixinplugin/Mixins.java @@ -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) diff --git a/src/main/java/com/cleanroommc/bogosorter/mixins/early/minecraft/MinecraftMixin.java b/src/main/java/com/cleanroommc/bogosorter/mixins/early/minecraft/MinecraftMixin.java index 2282cda4..e35bc1c1 100644 --- a/src/main/java/com/cleanroommc/bogosorter/mixins/early/minecraft/MinecraftMixin.java +++ b/src/main/java/com/cleanroommc/bogosorter/mixins/early/minecraft/MinecraftMixin.java @@ -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_); + } + } }