Skip to content

Commit

Permalink
load knife item lazily
Browse files Browse the repository at this point in the history
  • Loading branch information
PssbleTrngle committed Apr 18, 2024
1 parent 8b0ba1f commit dbc6f4b
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.possible_triangle.sliceanddice.mixins;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.possible_triangle.sliceanddice.compat.ModCompat;
import com.simibubi.create.content.contraptions.actors.harvester.HarvesterMovementBehaviour;
import net.minecraft.world.item.ItemStack;
Expand All @@ -13,15 +15,18 @@
public class HarvesterMovementBehaviourMixin {

@Unique
private static final ItemStack sliceanddice$TOOL = ModCompat.INSTANCE.ifLoaded(ModCompat.FARMERS_DELIGHT, () -> new ItemStack(ModItems.IRON_KNIFE.get()));
private static final Supplier<ItemStack> sliceanddice$TOOL = Suppliers.memoize(() -> {
return ModCompat.INSTANCE.ifLoaded(ModCompat.FARMERS_DELIGHT, () -> new ItemStack(ModItems.IRON_KNIFE.get()));
});

@ModifyVariable(
require = 0,
method = "visitNewPosition(Lcom/simibubi/create/content/contraptions/behaviour/MovementContext;Lnet/minecraft/core/BlockPos;)V",
at = @At("STORE")
)
private ItemStack overwriteDefaultItem(ItemStack stack) {
if (sliceanddice$TOOL != null) return sliceanddice$TOOL;
var tool = sliceanddice$TOOL.get();
if (tool != null) return tool;
return stack;
}

Expand Down

0 comments on commit dbc6f4b

Please sign in to comment.