Skip to content

Commit

Permalink
Alternative fix for invtweaks using optional methods that avoids dupl…
Browse files Browse the repository at this point in the history
…ication.
  • Loading branch information
c0508383 committed Aug 10, 2022
1 parent b599564 commit 6868404
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ public static InvTweaksContainerManager getContainerManager(InvTweaksContainerSe

// inv tweaks compat starts here

@Optional.Method(modid="inventorytweaks")
/*@Optional.Method(modid="inventorytweaks")
@Fix(returnSetting = EnumReturnSetting.ALWAYS)
public static boolean move(InvTweaksContainerSectionManager itcm, int srcIndex, int destIndex) {
if (CommonProxy.invTweaksDisableMove > 0) {
Expand All @@ -663,5 +663,5 @@ public static boolean move(InvTweaksContainerSectionManager itcm, int srcIndex,
}
return getContainerManager(itcm).move(getContainerSection(itcm), srcIndex, getContainerSection(itcm), destIndex);
}
}*/
}
39 changes: 38 additions & 1 deletion src/main/java/xonin/backhand/client/ClientTickHandler.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package xonin.backhand.client;

import cpw.mods.fml.common.Optional;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import invtweaks.InvTweaks;
import mods.battlegear2.BattlemodeHookContainerClass;
import mods.battlegear2.api.core.BattlegearUtils;
import mods.battlegear2.api.core.InventoryPlayerBattle;
Expand All @@ -19,17 +21,25 @@

public class ClientTickHandler {
public static int delay;
public static int swapDelay;
public static boolean prevInvTweaksAutoRefill;
public static boolean prevInvTweaksBreakRefill;

@SubscribeEvent
public void onKeyInputEvent(InputEvent.KeyInputEvent event) {
Minecraft mc = Minecraft.getMinecraft();
EntityClientPlayerMP player = mc.thePlayer;

if (ClientProxy.swapOffhand.getIsKeyPressed() && Keyboard.isKeyDown(Keyboard.getEventKey())) {
if (ClientProxy.swapOffhand.getIsKeyPressed() && Keyboard.isKeyDown(Keyboard.getEventKey()) && swapDelay <= 0) {
ItemStack offhandItem = ((InventoryPlayerBattle) player.inventory).getOffhandItem();
if (Backhand.isOffhandBlacklisted(player.getCurrentEquippedItem()) || Backhand.isOffhandBlacklisted(offhandItem)) {
return;
}
swapDelay = 5;
try {
this.getClass().getMethod("invTweaksSwapPatch");
invTweaksSwapPatch();
} catch (Exception ignored) {}

player.sendQueue.addToSendQueue(
new OffhandSwapPacket(player.getCurrentEquippedItem(), offhandItem, player).generatePacket()
Expand All @@ -39,6 +49,33 @@ public void onKeyInputEvent(InputEvent.KeyInputEvent event) {
}
}

@Optional.Method(modid="inventorytweaks")
public void invTweaksSwapPatch() {
prevInvTweaksAutoRefill = Boolean.parseBoolean(InvTweaks.getConfigManager().getConfig().getProperty("enableAutoRefill"));
prevInvTweaksBreakRefill = Boolean.parseBoolean(InvTweaks.getConfigManager().getConfig().getProperty("autoRefillBeforeBreak"));
InvTweaks.getConfigManager().getConfig().setProperty("enableAutoRefill", "false");
InvTweaks.getConfigManager().getConfig().setProperty("autoRefillBeforeBreak","false");
}

@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
if (swapDelay > 0) {
swapDelay--;
if (swapDelay == 0) {
try {
this.getClass().getMethod("restoreInvTweaksConfigs");
restoreInvTweaksConfigs();
} catch (Exception ignored) {}
}
}
}

@Optional.Method(modid="inventorytweaks")
public void restoreInvTweaksConfigs() {
InvTweaks.getConfigManager().getConfig().setProperty("enableAutoRefill",String.valueOf(prevInvTweaksAutoRefill));
InvTweaks.getConfigManager().getConfig().setProperty("autoRefillBeforeBreak",String.valueOf(prevInvTweaksBreakRefill));
}

@SideOnly(Side.CLIENT)
@SubscribeEvent
public void clientHelper(TickEvent.PlayerTickEvent event) {
Expand Down

0 comments on commit 6868404

Please sign in to comment.