forked from Meldexun/RLTweaker
-
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.
Add quark item linking cooldown patch
- Loading branch information
Showing
5 changed files
with
84 additions
and
0 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
40 changes: 40 additions & 0 deletions
40
src/main/java/com/charles445/rltweaker/asm/patch/PatchItemLinking.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.charles445.rltweaker.asm.patch; | ||
|
||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.JumpInsnNode; | ||
import org.objectweb.asm.tree.LabelNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.VarInsnNode; | ||
|
||
import com.charles445.rltweaker.asm.util.ASMUtil; | ||
import com.charles445.rltweaker.asm.util.TransformUtil; | ||
|
||
public class PatchItemLinking extends PatchManager { | ||
|
||
public PatchItemLinking() { | ||
super("Patch Item Linking"); | ||
|
||
this.add(new Patch(this, "vazkii.quark.management.feature.LinkItems", ClassWriter.COMPUTE_FRAMES) { | ||
@Override | ||
public void patch(ClassNode clazzNode) { | ||
MethodNode m_linkItem = this.findMethod(clazzNode, "linkItem"); | ||
|
||
MethodInsnNode onDisconnect = ASMUtil.findMethodInsn(m_linkItem, Opcodes.INVOKEVIRTUAL, "net/minecraft/network/NetHandlerPlayServer", "func_147231_a", "onDisconnect", "(Lnet/minecraft/util/text/ITextComponent;)V", 0); | ||
m_linkItem.instructions.set(onDisconnect, TransformUtil.createObfMethodInsn(Opcodes.INVOKEVIRTUAL, "net/minecraft/network/NetHandlerPlayServer", "func_194028_b", "(Lnet/minecraft/util/text/ITextComponent;)V", false)); | ||
|
||
LabelNode labelNode = new LabelNode(); | ||
TransformUtil.insertBeforeFirst(m_linkItem, ASMUtil.listOf( | ||
new VarInsnNode(Opcodes.ALOAD, 0), | ||
new MethodInsnNode(Opcodes.INVOKESTATIC, "com/charles445/rltweaker/hook/HookQuark", "tryLinkItem", "(Lnet/minecraft/entity/player/EntityPlayer;)Z", false), | ||
new JumpInsnNode(Opcodes.IFNE, labelNode), | ||
new InsnNode(Opcodes.RETURN), | ||
labelNode)); | ||
} | ||
}); | ||
} | ||
|
||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/charles445/rltweaker/hook/HookQuark.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,24 @@ | ||
package com.charles445.rltweaker.hook; | ||
|
||
import java.util.UUID; | ||
|
||
import com.charles445.rltweaker.config.ModConfig; | ||
|
||
import it.unimi.dsi.fastutil.objects.Object2LongMap; | ||
import it.unimi.dsi.fastutil.objects.Object2LongOpenHashMap; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
|
||
public class HookQuark { | ||
|
||
private static final Object2LongMap<UUID> lastTimeItemLinked = new Object2LongOpenHashMap<>(); | ||
|
||
public static boolean tryLinkItem(EntityPlayer player) { | ||
long lastTime = lastTimeItemLinked.getLong(player.getPersistentID()); | ||
if (player.world.getTotalWorldTime() < lastTime + ModConfig.server.quark.itemLinkingCooldown) { | ||
return false; | ||
} | ||
lastTimeItemLinked.put(player.getPersistentID(), player.world.getTotalWorldTime()); | ||
return true; | ||
} | ||
|
||
} |