From c052807773434876c8e4f0b4b51c84f4f1f60fd3 Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Wed, 16 Aug 2023 17:03:07 -0700 Subject: [PATCH] Fix copycat model modifying potentially immutable list - Perform minor mod initialization clean up - Bump version to patch E - Organize imports --- gradle.properties | 2 +- .../com/simibubi/create/AllRecipeTypes.java | 2 -- src/main/java/com/simibubi/create/Create.java | 19 ++++++++++--------- .../simibubi/create/compat/curios/Curios.java | 12 ++++++------ .../decoration/copycat/CopycatBarsModel.java | 8 +++++--- .../decoration/copycat/CopycatModel.java | 15 +++++++++++++-- .../equipment/armor/DivingHelmetItem.java | 4 ++-- .../equipment/armor/RemainingAirOverlay.java | 4 ++-- .../schematics/SchematicInstances.java | 10 ++-------- .../trains/bogey/BackupBogeyRenderer.java | 1 - .../content/trains/bogey/BogeyRenderer.java | 9 ++++----- .../trains/bogey/StandardBogeyRenderer.java | 1 - .../gametest/CreateGameTestHelper.java | 18 +++++++----------- .../gametest/tests/TestContraptions.java | 1 - .../gametest/tests/TestFluids.java | 2 -- .../gametest/tests/TestItems.java | 1 - 16 files changed, 52 insertions(+), 57 deletions(-) diff --git a/gradle.properties b/gradle.properties index 63d62e52f..6187a087b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs = -Xmx3G org.gradle.daemon = false # mod version info -mod_version = 0.5.1.c +mod_version = 0.5.1.e artifact_minecraft_version = 1.18.2 minecraft_version = 1.18.2 diff --git a/src/main/java/com/simibubi/create/AllRecipeTypes.java b/src/main/java/com/simibubi/create/AllRecipeTypes.java index 7553572aa..6479b6036 100644 --- a/src/main/java/com/simibubi/create/AllRecipeTypes.java +++ b/src/main/java/com/simibubi/create/AllRecipeTypes.java @@ -1,12 +1,10 @@ package com.simibubi.create; import java.util.Optional; -import java.util.Set; import java.util.function.Supplier; import org.jetbrains.annotations.Nullable; -import com.google.common.collect.ImmutableSet; import com.simibubi.create.compat.jei.ConversionRecipe; import com.simibubi.create.content.equipment.sandPaper.SandPaperPolishingRecipe; import com.simibubi.create.content.equipment.toolbox.ToolboxDyeingRecipe; diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index c5fbec2ba..e4747e5e8 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -20,7 +20,6 @@ import com.simibubi.create.content.kinetics.TorquePropagator; import com.simibubi.create.content.kinetics.mechanicalArm.AllArmInteractionPointTypes; import com.simibubi.create.content.redstone.displayLink.AllDisplayBehaviours; import com.simibubi.create.content.redstone.link.RedstoneLinkNetworkHandler; -import com.simibubi.create.content.schematics.SchematicInstances; import com.simibubi.create.content.schematics.ServerSchematicLoader; import com.simibubi.create.content.trains.GlobalRailwayManager; import com.simibubi.create.content.trains.bogey.BogeySizes; @@ -70,7 +69,7 @@ public class Create { public static final String ID = "create"; public static final String NAME = "Create"; - public static final String VERSION = "0.5.1c"; + public static final String VERSION = "0.5.1e"; public static final Logger LOGGER = LogUtils.getLogger(); @@ -125,21 +124,27 @@ public class Create { AllParticleTypes.register(modEventBus); AllStructureProcessorTypes.register(modEventBus); AllEntityDataSerializers.register(modEventBus); + AllPackets.registerPackets(); AllOreFeatureConfigEntries.init(); AllFeatures.register(modEventBus); AllPlacementModifiers.register(modEventBus); BuiltinRegistration.register(modEventBus); - BogeySizes.init(); - AllBogeyStyles.register(); AllConfigs.register(modLoadingContext); + // FIXME: some of these registrations are not thread-safe AllMovementBehaviours.registerDefaults(); AllInteractionBehaviours.registerDefaults(); AllDisplayBehaviours.registerDefaults(); ContraptionMovementSetting.registerDefaults(); AllArmInteractionPointTypes.register(); BlockSpoutingBehaviour.registerDefaults(); + BoilerHeaters.registerDefaults(); + BuiltinPotatoProjectileTypes.register(); + BogeySizes.init(); + AllBogeyStyles.register(); + // ---- + ComputerCraftProxy.register(); ForgeMod.enableMilkFluid(); @@ -153,19 +158,15 @@ public class Create { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> CreateClient.onCtorClient(modEventBus, forgeEventBus)); + // FIXME: this is not thread-safe Mods.CURIOS.executeIfInstalled(() -> () -> Curios.init(modEventBus, forgeEventBus)); } public static void init(final FMLCommonSetupEvent event) { - AllPackets.registerPackets(); - SchematicInstances.register(); - BuiltinPotatoProjectileTypes.register(); - event.enqueueWork(() -> { AttachedRegistry.unwrapAll(); AllAdvancements.register(); AllTriggers.register(); - BoilerHeaters.registerDefaults(); }); } diff --git a/src/main/java/com/simibubi/create/compat/curios/Curios.java b/src/main/java/com/simibubi/create/compat/curios/Curios.java index ff8212433..97eea93e2 100644 --- a/src/main/java/com/simibubi/create/compat/curios/Curios.java +++ b/src/main/java/com/simibubi/create/compat/curios/Curios.java @@ -1,9 +1,14 @@ package com.simibubi.create.compat.curios; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Optional; + import com.simibubi.create.AllItems; +import com.simibubi.create.AllTags; import com.simibubi.create.content.equipment.armor.BacktankUtil; import com.simibubi.create.content.equipment.goggles.GogglesItem; -import com.simibubi.create.AllTags; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; @@ -19,11 +24,6 @@ import top.theillusivec4.curios.api.SlotTypePreset; import top.theillusivec4.curios.api.type.capability.ICuriosItemHandler; import top.theillusivec4.curios.api.type.inventory.ICurioStacksHandler; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Optional; - public class Curios { /** diff --git a/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatBarsModel.java b/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatBarsModel.java index a26b7597d..681d891da 100644 --- a/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatBarsModel.java +++ b/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatBarsModel.java @@ -30,15 +30,14 @@ public class CopycatBarsModel extends CopycatModel { protected List getCroppedQuads(BlockState state, Direction side, Random rand, BlockState material, IModelData wrappedData) { BakedModel model = getModelOf(material); - List templateQuads = model.getQuads(material, null, rand, wrappedData); List superQuads = originalModel.getQuads(state, side, rand, wrappedData); - List quads = new ArrayList<>(); TextureAtlasSprite targetSprite = model.getParticleIcon(wrappedData); boolean vertical = state.getValue(CopycatPanelBlock.FACING) .getAxis() == Axis.Y; - if (side != null && (vertical || side.getAxis() == Axis.Y)) + if (side != null && (vertical || side.getAxis() == Axis.Y)) { + List templateQuads = model.getQuads(material, null, rand, wrappedData); for (int i = 0; i < templateQuads.size(); i++) { BakedQuad quad = templateQuads.get(i); if (quad.getDirection() != Direction.UP) @@ -46,10 +45,13 @@ public class CopycatBarsModel extends CopycatModel { targetSprite = quad.getSprite(); break; } + } if (targetSprite == null) return superQuads; + List quads = new ArrayList<>(); + for (int i = 0; i < superQuads.size(); i++) { BakedQuad quad = superQuads.get(i); TextureAtlasSprite original = quad.getSprite(); diff --git a/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatModel.java b/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatModel.java index 747f8838a..76c6e5c96 100644 --- a/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatModel.java +++ b/src/main/java/com/simibubi/create/content/decoration/copycat/CopycatModel.java @@ -1,5 +1,6 @@ package com.simibubi.create.content.decoration.copycat; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Random; @@ -107,14 +108,24 @@ public abstract class CopycatModel extends BakedModelWrapperWithData { // Rubidium: render side!=null versions of the base material during side==null, // to avoid getting culled away - if (side == null && state.getBlock() instanceof CopycatBlock ccb) + if (side == null && state.getBlock() instanceof CopycatBlock ccb) { + boolean immutable = true; for (Direction nonOcclusionSide : Iterate.directions) - if (ccb.shouldFaceAlwaysRender(state, nonOcclusionSide)) + if (ccb.shouldFaceAlwaysRender(state, nonOcclusionSide)) { + if (immutable) { + croppedQuads = new ArrayList<>(croppedQuads); + immutable = false; + } croppedQuads.addAll(getCroppedQuads(state, nonOcclusionSide, rand, material, wrappedData)); + } + } return croppedQuads; } + /** + * The returned list must not be mutated. + */ protected abstract List getCroppedQuads(BlockState state, Direction side, Random rand, BlockState material, IModelData wrappedData); diff --git a/src/main/java/com/simibubi/create/content/equipment/armor/DivingHelmetItem.java b/src/main/java/com/simibubi/create/content/equipment/armor/DivingHelmetItem.java index 173624e7f..4640f4671 100644 --- a/src/main/java/com/simibubi/create/content/equipment/armor/DivingHelmetItem.java +++ b/src/main/java/com/simibubi/create/content/equipment/armor/DivingHelmetItem.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.equipment.armor; +import java.util.List; + import com.simibubi.create.foundation.advancement.AllAdvancements; import net.minecraft.resources.ResourceLocation; @@ -20,8 +22,6 @@ import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; -import java.util.List; - @EventBusSubscriber public class DivingHelmetItem extends BaseArmorItem { public static final EquipmentSlot SLOT = EquipmentSlot.HEAD; diff --git a/src/main/java/com/simibubi/create/content/equipment/armor/RemainingAirOverlay.java b/src/main/java/com/simibubi/create/content/equipment/armor/RemainingAirOverlay.java index addce7844..939d39e09 100644 --- a/src/main/java/com/simibubi/create/content/equipment/armor/RemainingAirOverlay.java +++ b/src/main/java/com/simibubi/create/content/equipment/armor/RemainingAirOverlay.java @@ -1,5 +1,7 @@ package com.simibubi.create.content.equipment.armor; +import java.util.List; + import com.mojang.blaze3d.vertex.PoseStack; import com.simibubi.create.AllItems; import com.simibubi.create.foundation.gui.element.GuiGameElement; @@ -16,8 +18,6 @@ import net.minecraft.world.level.GameType; import net.minecraftforge.client.gui.ForgeIngameGui; import net.minecraftforge.client.gui.IIngameOverlay; -import java.util.List; - public class RemainingAirOverlay implements IIngameOverlay { public static final RemainingAirOverlay INSTANCE = new RemainingAirOverlay(); diff --git a/src/main/java/com/simibubi/create/content/schematics/SchematicInstances.java b/src/main/java/com/simibubi/create/content/schematics/SchematicInstances.java index e26d75e84..d0be247d6 100644 --- a/src/main/java/com/simibubi/create/content/schematics/SchematicInstances.java +++ b/src/main/java/com/simibubi/create/content/schematics/SchematicInstances.java @@ -23,19 +23,13 @@ import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemp public class SchematicInstances { - public static final WorldAttached> loadedSchematics; - - static { - loadedSchematics = new WorldAttached<>($ -> CacheBuilder.newBuilder() + private static final WorldAttached> LOADED_SCHEMATICS = new WorldAttached<>($ -> CacheBuilder.newBuilder() .expireAfterAccess(5, TimeUnit.MINUTES) .build()); - } - - public static void register() {} @Nullable public static SchematicWorld get(Level world, ItemStack schematic) { - Cache map = loadedSchematics.get(world); + Cache map = LOADED_SCHEMATICS.get(world); int hash = getHash(schematic); SchematicWorld ifPresent = map.getIfPresent(hash); if (ifPresent != null) diff --git a/src/main/java/com/simibubi/create/content/trains/bogey/BackupBogeyRenderer.java b/src/main/java/com/simibubi/create/content/trains/bogey/BackupBogeyRenderer.java index de321c63c..fd991fb04 100644 --- a/src/main/java/com/simibubi/create/content/trains/bogey/BackupBogeyRenderer.java +++ b/src/main/java/com/simibubi/create/content/trains/bogey/BackupBogeyRenderer.java @@ -3,7 +3,6 @@ package com.simibubi.create.content.trains.bogey; import com.jozufozu.flywheel.api.MaterialManager; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; - import com.simibubi.create.content.trains.entity.CarriageBogey; import net.minecraft.nbt.CompoundTag; diff --git a/src/main/java/com/simibubi/create/content/trains/bogey/BogeyRenderer.java b/src/main/java/com/simibubi/create/content/trains/bogey/BogeyRenderer.java index 749be8d56..8e1d806c7 100644 --- a/src/main/java/com/simibubi/create/content/trains/bogey/BogeyRenderer.java +++ b/src/main/java/com/simibubi/create/content/trains/bogey/BogeyRenderer.java @@ -6,11 +6,6 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.IntStream; -import com.mojang.math.Matrix3f; -import com.mojang.math.Matrix4f; -import com.mojang.math.Quaternion; -import com.simibubi.create.content.trains.entity.CarriageBogey; - import org.jetbrains.annotations.Nullable; import com.jozufozu.flywheel.api.MaterialManager; @@ -20,6 +15,10 @@ import com.jozufozu.flywheel.core.materials.model.ModelData; import com.jozufozu.flywheel.util.transform.Transform; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import com.mojang.math.Matrix3f; +import com.mojang.math.Matrix4f; +import com.mojang.math.Quaternion; +import com.simibubi.create.content.trains.entity.CarriageBogey; import com.simibubi.create.foundation.render.CachedBufferer; import com.simibubi.create.foundation.render.SuperByteBuffer; diff --git a/src/main/java/com/simibubi/create/content/trains/bogey/StandardBogeyRenderer.java b/src/main/java/com/simibubi/create/content/trains/bogey/StandardBogeyRenderer.java index 2631326c2..8b2cc6f7e 100644 --- a/src/main/java/com/simibubi/create/content/trains/bogey/StandardBogeyRenderer.java +++ b/src/main/java/com/simibubi/create/content/trains/bogey/StandardBogeyRenderer.java @@ -8,7 +8,6 @@ import static com.simibubi.create.AllPartialModels.LARGE_BOGEY_WHEELS; import static com.simibubi.create.AllPartialModels.SMALL_BOGEY_WHEELS; import com.jozufozu.flywheel.api.MaterialManager; -import com.jozufozu.flywheel.util.transform.Transform; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; import com.simibubi.create.AllBlocks; diff --git a/src/main/java/com/simibubi/create/infrastructure/gametest/CreateGameTestHelper.java b/src/main/java/com/simibubi/create/infrastructure/gametest/CreateGameTestHelper.java index f9ae8c79d..be60c8ece 100644 --- a/src/main/java/com/simibubi/create/infrastructure/gametest/CreateGameTestHelper.java +++ b/src/main/java/com/simibubi/create/infrastructure/gametest/CreateGameTestHelper.java @@ -5,21 +5,17 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; -import com.simibubi.create.content.contraptions.Contraption; -import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovement; -import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovingInteraction; -import com.simibubi.create.content.contraptions.behaviour.MovementContext; -import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity; - -import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity; - -import net.minecraftforge.registries.ForgeRegistries; - import org.apache.commons.lang3.tuple.MutablePair; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import com.simibubi.create.AllBlockEntityTypes; +import com.simibubi.create.content.contraptions.Contraption; +import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovement; +import com.simibubi.create.content.contraptions.actors.contraptionControls.ContraptionControlsMovingInteraction; +import com.simibubi.create.content.contraptions.behaviour.MovementContext; +import com.simibubi.create.content.kinetics.gauge.SpeedGaugeBlockEntity; +import com.simibubi.create.content.kinetics.gauge.StressGaugeBlockEntity; import com.simibubi.create.content.logistics.tunnel.BrassTunnelBlockEntity.SelectionMode; import com.simibubi.create.content.redstone.nixieTube.NixieTubeBlockEntity; import com.simibubi.create.foundation.blockEntity.IMultiBlockEntityContainer; @@ -35,7 +31,6 @@ import it.unimi.dsi.fastutil.objects.Object2LongArrayMap; import it.unimi.dsi.fastutil.objects.Object2LongMap; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.Registry; import net.minecraft.gametest.framework.GameTestHelper; import net.minecraft.gametest.framework.GameTestInfo; import net.minecraft.server.level.ServerLevel; @@ -62,6 +57,7 @@ import net.minecraftforge.fluids.capability.IFluidHandler.FluidAction; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemHandlerHelper; +import net.minecraftforge.registries.ForgeRegistries; /** * A helper class expanding the functionality of {@link GameTestHelper}. diff --git a/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestContraptions.java b/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestContraptions.java index c38956676..fe12592f7 100644 --- a/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestContraptions.java +++ b/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestContraptions.java @@ -14,7 +14,6 @@ import com.simibubi.create.infrastructure.gametest.CreateGameTestHelper; import com.simibubi.create.infrastructure.gametest.GameTestGroup; import it.unimi.dsi.fastutil.objects.Object2LongMap; - import net.minecraft.core.BlockPos; import net.minecraft.gametest.framework.GameTest; import net.minecraft.world.entity.EntityType; diff --git a/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestFluids.java b/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestFluids.java index a0a4097e0..4b0e7e4fc 100644 --- a/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestFluids.java +++ b/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestFluids.java @@ -14,8 +14,6 @@ import com.simibubi.create.infrastructure.gametest.CreateGameTestHelper; import com.simibubi.create.infrastructure.gametest.GameTestGroup; import net.minecraft.core.BlockPos; -import net.minecraft.core.Holder; -import net.minecraft.core.Registry; import net.minecraft.gametest.framework.GameTest; import net.minecraft.gametest.framework.GameTestAssertException; import net.minecraft.tags.BlockTags; diff --git a/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestItems.java b/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestItems.java index 0ab535a93..6f0c614f8 100644 --- a/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestItems.java +++ b/src/main/java/com/simibubi/create/infrastructure/gametest/tests/TestItems.java @@ -21,7 +21,6 @@ import com.simibubi.create.infrastructure.gametest.GameTestGroup; import it.unimi.dsi.fastutil.objects.Object2LongMap; import net.minecraft.Util; import net.minecraft.core.BlockPos; -import net.minecraft.core.Registry; import net.minecraft.gametest.framework.GameTest; import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.item.EnchantedBookItem;