diff --git a/src/main/java/com/simibubi/create/content/kinetics/belt/transport/TransportedItemStack.java b/src/main/java/com/simibubi/create/content/kinetics/belt/transport/TransportedItemStack.java index 9756cbf46d..6185fdf323 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/belt/transport/TransportedItemStack.java +++ b/src/main/java/com/simibubi/create/content/kinetics/belt/transport/TransportedItemStack.java @@ -81,8 +81,10 @@ public class TransportedItemStack implements Comparable { nbt.putInt("Angle", angle); nbt.putInt("InDirection", insertedFrom.get3DDataValue()); - if (processedBy != null && processedBy != AllFanProcessingTypes.NONE) { + if (processedBy != null) { ResourceLocation key = CreateBuiltInRegistries.FAN_PROCESSING_TYPE.getKey(processedBy); + if (key == null) + throw new IllegalArgumentException("Could not get id for FanProcessingType " + processedBy + "!"); nbt.putString("FanProcessingType", key.toString()); nbt.putInt("FanProcessingTime", processingTime); diff --git a/src/main/java/com/simibubi/create/content/kinetics/fan/AirCurrent.java b/src/main/java/com/simibubi/create/content/kinetics/fan/AirCurrent.java index a6ff7a4a8b..735b62cea1 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/fan/AirCurrent.java +++ b/src/main/java/com/simibubi/create/content/kinetics/fan/AirCurrent.java @@ -5,12 +5,12 @@ import java.util.Iterator; import java.util.List; import org.apache.commons.lang3.tuple.Pair; +import org.jetbrains.annotations.Nullable; import com.simibubi.create.AllTags; import com.simibubi.create.content.decoration.copycat.CopycatBlock; import com.simibubi.create.content.kinetics.belt.behaviour.TransportedItemStackHandlerBehaviour; import com.simibubi.create.content.kinetics.belt.behaviour.TransportedItemStackHandlerBehaviour.TransportedResult; -import com.simibubi.create.content.kinetics.fan.processing.AllFanProcessingTypes; import com.simibubi.create.content.kinetics.fan.processing.FanProcessing; import com.simibubi.create.content.kinetics.fan.processing.FanProcessingType; import com.simibubi.create.foundation.advancement.AllAdvancements; @@ -108,7 +108,7 @@ public class AirCurrent { FanProcessingType processingType = getTypeAt((float) entityDistance); - if (processingType == AllFanProcessingTypes.NONE) + if (processingType == null) continue; if (entity instanceof ItemEntity itemEntity) { @@ -140,7 +140,7 @@ public class AirCurrent { TransportedItemStackHandlerBehaviour handler = pair.getKey(); Level world = handler.getWorld(); FanProcessingType processingType = pair.getRight(); - if (processingType == AllFanProcessingTypes.NONE) + if (processingType == null) continue; handler.handleProcessingOnAllItems(transported -> { @@ -178,7 +178,7 @@ public class AirCurrent { // Determine segments with transported fluids/gases segments.clear(); AirCurrentSegment currentSegment = null; - FanProcessingType type = AllFanProcessingTypes.NONE; + FanProcessingType type = null; int limit = getLimit(); int searchStart = pushing ? 1 : limit; @@ -189,7 +189,7 @@ public class AirCurrent { for (int i = searchStart; i * searchStep <= searchEnd * searchStep; i += searchStep) { BlockPos currentPos = start.relative(direction, i); FanProcessingType newType = FanProcessingType.getAt(world, currentPos); - if (newType != AllFanProcessingTypes.NONE) { + if (newType != null) { type = newType; } if (currentSegment == null) { @@ -322,7 +322,7 @@ public class AirCurrent { BlockEntityBehaviour.get(world, pos, TransportedItemStackHandlerBehaviour.TYPE); if (behaviour != null) { FanProcessingType type = FanProcessingType.getAt(world, pos); - if (type == AllFanProcessingTypes.NONE) + if (type == null) type = segmentType; affectedItemHandlers.add(Pair.of(behaviour, type)); } @@ -339,6 +339,7 @@ public class AirCurrent { .getEntities(null, bounds); } + @Nullable public FanProcessingType getTypeAt(float offset) { if (offset >= 0 && offset <= maxDistance) { if (pushing) { @@ -355,10 +356,11 @@ public class AirCurrent { } } } - return AllFanProcessingTypes.NONE; + return null; } private static class AirCurrentSegment { + @Nullable private FanProcessingType type; private int startOffset; private int endOffset; diff --git a/src/main/java/com/simibubi/create/content/kinetics/fan/AirFlowParticle.java b/src/main/java/com/simibubi/create/content/kinetics/fan/AirFlowParticle.java index f39f250855..d7bd952a0e 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/fan/AirFlowParticle.java +++ b/src/main/java/com/simibubi/create/content/kinetics/fan/AirFlowParticle.java @@ -1,8 +1,8 @@ package com.simibubi.create.content.kinetics.fan; import javax.annotation.Nonnull; +import javax.annotation.Nullable; -import com.simibubi.create.content.kinetics.fan.processing.AllFanProcessingTypes; import com.simibubi.create.content.kinetics.fan.processing.FanProcessingType; import net.createmod.catnip.math.VecHelper; @@ -78,7 +78,7 @@ public class AirFlowParticle extends SimpleAnimatedParticle { motion = motion.scale(airCurrent.maxDistance - (distance - 1f)).scale(.5f); FanProcessingType type = getType(distance); - if (type == AllFanProcessingTypes.NONE) { + if (type == null) { setColor(0xEEEEEE); setAlpha(.25f); selectSprite((int) Mth.clamp((distance / airCurrent.maxDistance) * 8 + random.nextInt(4), @@ -100,9 +100,10 @@ public class AirFlowParticle extends SimpleAnimatedParticle { } } + @Nullable private FanProcessingType getType(double distance) { if (source.getAirCurrent() == null) - return AllFanProcessingTypes.NONE; + return null; return source.getAirCurrent().getTypeAt((float) distance); } diff --git a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java index cd58d16ffe..02bc9e5dfa 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java +++ b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/AllFanProcessingTypes.java @@ -62,7 +62,6 @@ import net.minecraftforge.registries.DeferredRegister; public class AllFanProcessingTypes { private static final DeferredRegister REGISTER = DeferredRegister.create(CreateRegistries.FAN_PROCESSING_TYPE, Create.ID); - public static final NoneType NONE = register("none", new NoneType()); public static final BlastingType BLASTING = register("blasting", new BlastingType()); public static final HauntingType HAUNTING = register("haunting", new HauntingType()); public static final SmokingType SMOKING = register("smoking", new SmokingType()); @@ -72,7 +71,6 @@ public class AllFanProcessingTypes { static { Object2ReferenceOpenHashMap map = new Object2ReferenceOpenHashMap<>(); - map.put("NONE", NONE); map.put("BLASTING", BLASTING); map.put("HAUNTING", HAUNTING); map.put("SMOKING", SMOKING); @@ -95,6 +93,7 @@ public class AllFanProcessingTypes { return LEGACY_NAME_MAP.get(name); } + @Nullable public static FanProcessingType parseLegacy(String str) { FanProcessingType type = ofLegacyName(str); if (type != null) { diff --git a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessing.java b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessing.java index 53a1448084..6836ba9157 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessing.java +++ b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessing.java @@ -96,6 +96,8 @@ public class FanProcessing { if (!processing.contains("Type") || AllFanProcessingTypes.parseLegacy(processing.getString("Type")) != type) { ResourceLocation key = CreateBuiltInRegistries.FAN_PROCESSING_TYPE.getKey(type); + if (key == null) + throw new IllegalArgumentException("Could not get id for FanProcessingType " + type + "!"); processing.putString("Type", key.toString()); int timeModifierForStackSize = ((entity.getItem() diff --git a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessingType.java b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessingType.java index 470c855c02..6ef09a0a42 100644 --- a/src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessingType.java +++ b/src/main/java/com/simibubi/create/content/kinetics/fan/processing/FanProcessingType.java @@ -31,25 +31,19 @@ public interface FanProcessingType { void affectEntity(Entity entity, Level level); + @Nullable static FanProcessingType parse(String str) { - ResourceLocation id = ResourceLocation.tryParse(str); - if (id == null) { - return AllFanProcessingTypes.NONE; - } - FanProcessingType type = CreateBuiltInRegistries.FAN_PROCESSING_TYPE.get(id); - if (type == null) { - return AllFanProcessingTypes.NONE; - } - return type; + return CreateBuiltInRegistries.FAN_PROCESSING_TYPE.get(ResourceLocation.tryParse(str)); } + @Nullable static FanProcessingType getAt(Level level, BlockPos pos) { for (FanProcessingType type : FanProcessingTypeRegistry.getSortedTypesView()) { if (type.isValidAt(level, pos)) { return type; } } - return AllFanProcessingTypes.NONE; + return null; } interface AirFlowParticleAccess {