Skip to content

Commit 7e8fdb0

Browse files
committed
Do not allow missing items to be dropped by blocks.
1 parent 7cbc73a commit 7e8fdb0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

loader/src/main/java/com/fox2code/foxloader/loader/ModLoader.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import com.fox2code.foxloader.event.FoxLoaderEvents;
3333
import com.fox2code.foxloader.event.client.GuiScreenInitEvent;
3434
import com.fox2code.foxloader.event.lifecycle.LifecycleStartEvent;
35-
import com.fox2code.foxloader.event.movement.PlayerJumpingEvent;
36-
import com.fox2code.foxloader.event.movement.PlayerSneakingEvent;
3735
import com.fox2code.foxloader.internal.InternalTranslateHooks;
3836
import com.fox2code.foxloader.launcher.FoxLauncher;
3937
import com.fox2code.foxloader.loader.packet.LoaderNetworkManager;

patching/src/main/java/com/fox2code/foxloader/patching/game/RegistryPatch.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,27 @@ private static void patchBlock(ClassNode classNode) {
949949
prependHarvestBlock.add(new JumpInsnNode(IF_ICMPGE, skipStatIncrease));
950950
TransformerUtils.insertToBeginningOfCode(harvestBlock, prependHarvestBlock);
951951
harvestBlock.instructions.insert(addStat, skipStatIncrease);
952+
// dropBlockAsItem_do fix
953+
MethodNode dropBlockAsItem_do = TransformerUtils.getMethod(classNode, "dropBlockAsItem_do");
954+
JumpInsnNode dropBlockAsItem_doCheck = null;
955+
for (AbstractInsnNode abstractInsnNode : dropBlockAsItem_do.instructions) {
956+
if (abstractInsnNode.getOpcode() == IFNE) {
957+
dropBlockAsItem_doCheck = (JumpInsnNode) abstractInsnNode;
958+
break;
959+
}
960+
}
961+
Objects.requireNonNull(dropBlockAsItem_doCheck);
962+
InsnList dropBlockAsItem_doNewChecks = new InsnList();
963+
dropBlockAsItem_doNewChecks.add(new VarInsnNode(ALOAD, 5));
964+
dropBlockAsItem_doNewChecks.add(new JumpInsnNode(
965+
IFNULL, dropBlockAsItem_doCheck.label));
966+
dropBlockAsItem_doNewChecks.add(new VarInsnNode(ALOAD, 5));
967+
dropBlockAsItem_doNewChecks.add(new MethodInsnNode(INVOKESTATIC,
968+
GameRegistry, "isMissingItemStack", "(L" + ItemStack + ";)Z"));
969+
dropBlockAsItem_doNewChecks.add(new JumpInsnNode(
970+
IFNE, dropBlockAsItem_doCheck.label));
971+
dropBlockAsItem_do.instructions.insert(
972+
dropBlockAsItem_doCheck, dropBlockAsItem_doNewChecks);
952973
// getRegisterFLTab
953974
injectGetRegisterFLTab(classNode, "MISCELLANEOUS", true);
954975
injectGetCreativeTab(classNode);

0 commit comments

Comments
 (0)