Skip to content

Commit

Permalink
Add quark item linking cooldown patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldexun committed Aug 9, 2023
1 parent bd4872b commit 3b7d98f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/charles445/rltweaker/asm/RLTweakerASM.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.charles445.rltweaker.asm.patch.PatchFixOldHippocampus;
import com.charles445.rltweaker.asm.patch.PatchHopper;
import com.charles445.rltweaker.asm.patch.PatchItemFrameDupe;
import com.charles445.rltweaker.asm.patch.PatchItemLinking;
import com.charles445.rltweaker.asm.patch.PatchLessCollisions;
import com.charles445.rltweaker.asm.patch.PatchLycanitesDupe;
import com.charles445.rltweaker.asm.patch.PatchMyrmexQueenHiveSpam;
Expand Down Expand Up @@ -442,6 +443,11 @@ private void createPatches()
new PatchFallingBlockPortalDupe();
}

if(ASMConfig.getBoolean("general.patches.patchItemLinking", false))
{
new PatchItemLinking();
}

//new PatchForgeNetwork();
}

Expand Down
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));
}
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,11 @@ public class ConfigQuark
@RLConfig.RLCraftTwoEightTwo("false")
@RLConfig.RLCraftTwoNine("true")
public boolean ancientTomesAlternateBehavior = false;

@Config.Comment("Server side item linking cooldown (in ticks). Requires 'patchItemLinking' to be true!")
@Config.Name("Item Linking Cooldown")
@RLConfig.ImprovementsOnly("100")
@RLConfig.RLCraftTwoEightTwo("100")
@RLConfig.RLCraftTwoNine("100")
public int itemLinkingCooldown = 100;
}
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,11 @@ public class PatchConfig
@RLConfig.RLCraftTwoEightTwo("true")
@RLConfig.RLCraftTwoNine("true")
public boolean patchFallingBlockPortalDupe = true;

@Config.RequiresMcRestart
@Config.Comment("Fix for item linking from Quark.")
@RLConfig.ImprovementsOnly("true")
@RLConfig.RLCraftTwoEightTwo("true")
@RLConfig.RLCraftTwoNine("true")
public boolean patchItemLinking = true;
}
24 changes: 24 additions & 0 deletions src/main/java/com/charles445/rltweaker/hook/HookQuark.java
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;
}

}

0 comments on commit 3b7d98f

Please sign in to comment.