diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltHelper.java b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltHelper.java index 07430e5e7..913ff2c1d 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/BeltHelper.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/BeltHelper.java @@ -1,11 +1,16 @@ package com.simibubi.create.content.kinetics.belt; +import java.util.Map; + import com.simibubi.create.AllTags.AllItemTags; import com.simibubi.create.foundation.utility.VecHelper; +import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; import net.minecraft.core.BlockPos; import net.minecraft.core.Vec3i; +import net.minecraft.server.packs.resources.ResourceManagerReloadListener; import net.minecraft.util.Mth; +import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelAccessor; @@ -16,9 +21,13 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler; public class BeltHelper { + public static Map uprightCache = new Object2BooleanOpenHashMap<>(); + public static final ResourceManagerReloadListener LISTENER = resourceManager -> uprightCache.clear(); + public static boolean isItemUpright(ItemStack stack) { - return stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY) - .isPresent() || AllItemTags.UPRIGHT_ON_BELT.matches(stack); + return uprightCache.computeIfAbsent(stack.getItem(), + item -> stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY) + .isPresent() || AllItemTags.UPRIGHT_ON_BELT.matches(stack)); } public static BeltBlockEntity getSegmentBE(LevelAccessor world, BlockPos pos) { diff --git a/src/main/java/com/simibubi/create/content/kinetics/turntable/TurntableHandler.java b/src/main/java/com/simibubi/create/content/kinetics/turntable/TurntableHandler.java index 5fca562e3..9c76d5393 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/turntable/TurntableHandler.java +++ b/src/main/java/com/simibubi/create/content/kinetics/turntable/TurntableHandler.java @@ -16,6 +16,8 @@ public class TurntableHandler { Minecraft mc = Minecraft.getInstance(); BlockPos pos = mc.player.blockPosition(); + if (mc.gameMode == null) + return; if (!AllBlocks.TURNTABLE.has(mc.level.getBlockState(pos))) return; if (!mc.player.isOnGround()) diff --git a/src/main/java/com/simibubi/create/foundation/ClientResourceReloadListener.java b/src/main/java/com/simibubi/create/foundation/ClientResourceReloadListener.java index c0e81e199..32ae579fb 100644 --- a/src/main/java/com/simibubi/create/foundation/ClientResourceReloadListener.java +++ b/src/main/java/com/simibubi/create/foundation/ClientResourceReloadListener.java @@ -1,6 +1,7 @@ package com.simibubi.create.foundation; import com.simibubi.create.CreateClient; +import com.simibubi.create.content.kinetics.belt.BeltHelper; import com.simibubi.create.foundation.sound.SoundScapes; import com.simibubi.create.foundation.utility.LangNumberFormat; @@ -14,6 +15,7 @@ public class ClientResourceReloadListener implements ResourceManagerReloadListen CreateClient.invalidateRenderers(); SoundScapes.invalidateAll(); LangNumberFormat.numberFormat.update(); + BeltHelper.uprightCache.clear(); } } diff --git a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java index e0ec36b06..e3db3c85e 100644 --- a/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java +++ b/src/main/java/com/simibubi/create/foundation/events/CommonEvents.java @@ -11,6 +11,7 @@ import com.simibubi.create.content.equipment.toolbox.ToolboxHandler; import com.simibubi.create.content.equipment.wrench.WrenchItem; import com.simibubi.create.content.equipment.zapper.ZapperInteractionHandler; import com.simibubi.create.content.equipment.zapper.ZapperItem; +import com.simibubi.create.content.kinetics.belt.BeltHelper; import com.simibubi.create.content.redstone.link.controller.LinkedControllerServerHandler; import com.simibubi.create.content.trains.entity.CarriageEntityHandler; import com.simibubi.create.foundation.ModFilePackResources; @@ -171,6 +172,7 @@ public class CommonEvents { public static void addReloadListeners(AddReloadListenerEvent event) { event.addListener(RecipeFinder.LISTENER); event.addListener(PotatoProjectileTypeManager.ReloadListener.INSTANCE); + event.addListener(BeltHelper.LISTENER); } @SubscribeEvent diff --git a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java index d96c52953..971d0072a 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java +++ b/src/main/java/com/simibubi/create/foundation/utility/NBTProcessors.java @@ -91,9 +91,6 @@ public final class NBTProcessors { .stream() .filter(NBTProcessors::isUnsafeItemNBTKey) .forEach(copy::removeTagKey); - if (copy.getTag() - .isEmpty()) - copy.setTag(null); return copy; }