From 731f9f0a8a8620f12098547a0717204269134cad Mon Sep 17 00:00:00 2001 From: kirderf1 Date: Wed, 3 Jul 2024 11:17:24 +0200 Subject: [PATCH] Util package cleanup (#624) Unneeded things were removed, code was cleaned up, and classes were moved to relevant existing packages. --- .../data/forge/tags/blocks/terracotta.json | 37 ---- .../data/forge/tags/items/terracotta.json | 37 ---- .../recipes/grist_costs/terracotta_tag.json | 2 +- .../java/com/mraof/minestuck/Minestuck.java | 4 +- .../mraof/minestuck/alchemy/GristHelper.java | 20 ++- .../minestuck/api/alchemy/GristType.java | 8 +- .../minestuck/block/CassettePlayerBlock.java | 3 +- .../minestuck/block/CustomShapeBlock.java | 3 +- .../{util => block}/CustomVoxelShape.java | 2 +- .../block/DirectionalCustomShapeBlock.java | 3 +- .../block/LotusTimeCapsuleBlock.java | 3 +- .../mraof/minestuck/block/MSBlockShapes.java | 1 - .../com/mraof/minestuck/block/MSBlocks.java | 1 - .../com/mraof/minestuck/block/SpikeBlock.java | 1 - .../block/machine/AlchemiterBlock.java | 4 +- .../block/machine/CruxtruderBlock.java | 4 +- .../minestuck/block/machine/MachineBlock.java | 4 +- .../block/machine/PunchDesignixBlock.java | 4 +- .../block/machine/TotemLatheBlock.java | 4 +- .../block/redstone/ItemMagnetBlock.java | 4 +- .../blockentity/ComputerBlockEntity.java | 6 +- .../machine/AlchemiterBlockEntity.java | 9 +- .../machine/MiniAlchemiterBlockEntity.java | 7 +- .../machine/PunchDesignixBlockEntity.java | 15 +- .../machine/TotemLatheBlockEntity.java | 15 +- ...ider.java => BoondollarPriceProvider.java} | 35 ++-- .../mraof/minestuck/data/MinestuckData.java | 2 +- .../recipe/MinestuckGristCostsProvider.java | 4 +- .../data/tag/MinestuckBlockTagsProvider.java | 2 - .../data/tag/MinestuckItemTagsProvider.java | 1 - .../entity/carapacian/PawnEntity.java | 17 +- .../entity/consort/BoondollarPriceRecipe.java | 26 +++ .../entity/consort/BoondollarPrices.java | 84 +++++++++ .../entity/consort/ConsortEntity.java | 18 +- .../entity/consort/ConsortRewardHandler.java | 5 +- .../minestuck/entity/dialogue/Dialogue.java | 23 +-- .../dialogue/DialogueAnimationData.java | 16 +- .../minestuck/entity/dialogue/Trigger.java | 10 +- .../entity/dialogue/condition/Condition.java | 11 +- .../minestuck/entity/item/GristEntity.java | 7 +- .../entity/underling/BasiliskEntity.java | 16 +- .../entity/underling/GiclopsEntity.java | 18 +- .../minestuck/entity/underling/ImpEntity.java | 19 +- .../entity/underling/LichEntity.java | 16 +- .../entity/underling/OgreEntity.java | 18 +- .../entity/underling/UnderlingEntity.java | 6 +- .../mraof/minestuck/entry/EntryProcess.java | 4 +- .../mraof/minestuck/entry/PostEntryTask.java | 81 ++++----- .../item/IncompleteSburbCodeItem.java | 51 +++++- .../MSDispenserBehaviours.java} | 5 +- .../skaianet/DataCheckerManager.java | 1 - .../DataCheckerPermission.java | 30 ++-- .../minestuck/skaianet/SburbPlayerData.java | 10 +- .../util/AnimationControllerUtil.java | 25 --- .../util/BoondollarPriceManager.java | 80 --------- .../minestuck/util/BoondollarPricing.java | 58 ------- .../com/mraof/minestuck/util/CoordPair.java | 25 +-- .../mraof/minestuck/util/ExtraForgeTags.java | 8 +- .../mraof/minestuck/util/LazyInstance.java | 26 --- .../com/mraof/minestuck/util/MSNBTUtil.java | 164 ------------------ .../mraof/minestuck/util/MSSoundEvents.java | 4 +- .../minestuck/util/PositionTeleporter.java | 26 --- .../util/PreservingOptionalFieldCodec.java | 84 --------- .../mraof/minestuck/util/WorldEventUtil.java | 19 -- .../world/gen/feature/MesaFeature.java | 14 +- .../world/gen/feature/RockSpikeFeature.java | 12 +- .../world/lands/LandTypeExtensions.java | 8 +- .../minestuck/world/storage/MSExtraData.java | 11 +- 68 files changed, 430 insertions(+), 871 deletions(-) delete mode 100644 src/main/generated/resources/data/forge/tags/blocks/terracotta.json delete mode 100644 src/main/generated/resources/data/forge/tags/items/terracotta.json rename src/main/java/com/mraof/minestuck/{util => block}/CustomVoxelShape.java (98%) rename src/main/java/com/mraof/minestuck/data/{BoondollarPricingProvider.java => BoondollarPriceProvider.java} (87%) create mode 100644 src/main/java/com/mraof/minestuck/entity/consort/BoondollarPriceRecipe.java create mode 100644 src/main/java/com/mraof/minestuck/entity/consort/BoondollarPrices.java rename src/main/java/com/mraof/minestuck/{util/DispenserBehaviourUtil.java => item/MSDispenserBehaviours.java} (93%) rename src/main/java/com/mraof/minestuck/{util => skaianet}/DataCheckerPermission.java (79%) delete mode 100644 src/main/java/com/mraof/minestuck/util/AnimationControllerUtil.java delete mode 100644 src/main/java/com/mraof/minestuck/util/BoondollarPriceManager.java delete mode 100644 src/main/java/com/mraof/minestuck/util/BoondollarPricing.java delete mode 100644 src/main/java/com/mraof/minestuck/util/LazyInstance.java delete mode 100644 src/main/java/com/mraof/minestuck/util/MSNBTUtil.java delete mode 100644 src/main/java/com/mraof/minestuck/util/PositionTeleporter.java delete mode 100644 src/main/java/com/mraof/minestuck/util/PreservingOptionalFieldCodec.java delete mode 100644 src/main/java/com/mraof/minestuck/util/WorldEventUtil.java diff --git a/src/main/generated/resources/data/forge/tags/blocks/terracotta.json b/src/main/generated/resources/data/forge/tags/blocks/terracotta.json deleted file mode 100644 index 6db94441cc..0000000000 --- a/src/main/generated/resources/data/forge/tags/blocks/terracotta.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "values": [ - "minecraft:terracotta", - "minecraft:black_glazed_terracotta", - "minecraft:black_terracotta", - "minecraft:blue_glazed_terracotta", - "minecraft:blue_terracotta", - "minecraft:brown_glazed_terracotta", - "minecraft:brown_terracotta", - "minecraft:cyan_glazed_terracotta", - "minecraft:cyan_terracotta", - "minecraft:gray_glazed_terracotta", - "minecraft:gray_terracotta", - "minecraft:green_glazed_terracotta", - "minecraft:green_terracotta", - "minecraft:light_blue_glazed_terracotta", - "minecraft:light_blue_terracotta", - "minecraft:light_gray_glazed_terracotta", - "minecraft:light_gray_terracotta", - "minecraft:lime_glazed_terracotta", - "minecraft:lime_terracotta", - "minecraft:magenta_glazed_terracotta", - "minecraft:magenta_terracotta", - "minecraft:orange_glazed_terracotta", - "minecraft:orange_terracotta", - "minecraft:pink_glazed_terracotta", - "minecraft:pink_terracotta", - "minecraft:purple_glazed_terracotta", - "minecraft:purple_terracotta", - "minecraft:red_glazed_terracotta", - "minecraft:red_terracotta", - "minecraft:white_glazed_terracotta", - "minecraft:white_terracotta", - "minecraft:yellow_glazed_terracotta", - "minecraft:yellow_terracotta" - ] -} \ No newline at end of file diff --git a/src/main/generated/resources/data/forge/tags/items/terracotta.json b/src/main/generated/resources/data/forge/tags/items/terracotta.json deleted file mode 100644 index 6db94441cc..0000000000 --- a/src/main/generated/resources/data/forge/tags/items/terracotta.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "values": [ - "minecraft:terracotta", - "minecraft:black_glazed_terracotta", - "minecraft:black_terracotta", - "minecraft:blue_glazed_terracotta", - "minecraft:blue_terracotta", - "minecraft:brown_glazed_terracotta", - "minecraft:brown_terracotta", - "minecraft:cyan_glazed_terracotta", - "minecraft:cyan_terracotta", - "minecraft:gray_glazed_terracotta", - "minecraft:gray_terracotta", - "minecraft:green_glazed_terracotta", - "minecraft:green_terracotta", - "minecraft:light_blue_glazed_terracotta", - "minecraft:light_blue_terracotta", - "minecraft:light_gray_glazed_terracotta", - "minecraft:light_gray_terracotta", - "minecraft:lime_glazed_terracotta", - "minecraft:lime_terracotta", - "minecraft:magenta_glazed_terracotta", - "minecraft:magenta_terracotta", - "minecraft:orange_glazed_terracotta", - "minecraft:orange_terracotta", - "minecraft:pink_glazed_terracotta", - "minecraft:pink_terracotta", - "minecraft:purple_glazed_terracotta", - "minecraft:purple_terracotta", - "minecraft:red_glazed_terracotta", - "minecraft:red_terracotta", - "minecraft:white_glazed_terracotta", - "minecraft:white_terracotta", - "minecraft:yellow_glazed_terracotta", - "minecraft:yellow_terracotta" - ] -} \ No newline at end of file diff --git a/src/main/generated/resources/data/minestuck/recipes/grist_costs/terracotta_tag.json b/src/main/generated/resources/data/minestuck/recipes/grist_costs/terracotta_tag.json index 15f9bbdbe1..3356adeea2 100644 --- a/src/main/generated/resources/data/minestuck/recipes/grist_costs/terracotta_tag.json +++ b/src/main/generated/resources/data/minestuck/recipes/grist_costs/terracotta_tag.json @@ -2,7 +2,7 @@ "type": "minestuck:source_grist_cost", "grist_cost": {}, "ingredient": { - "tag": "forge:terracotta" + "tag": "minecraft:terracotta" }, "sources": [ "minecraft:clay" diff --git a/src/main/java/com/mraof/minestuck/Minestuck.java b/src/main/java/com/mraof/minestuck/Minestuck.java index 7dc9a99cd4..e565202290 100644 --- a/src/main/java/com/mraof/minestuck/Minestuck.java +++ b/src/main/java/com/mraof/minestuck/Minestuck.java @@ -23,11 +23,11 @@ import com.mraof.minestuck.inventory.MSMenuTypes; import com.mraof.minestuck.inventory.captchalogue.ModusTypes; import com.mraof.minestuck.item.MSCreativeTabs; +import com.mraof.minestuck.item.MSDispenserBehaviours; import com.mraof.minestuck.item.MSItems; import com.mraof.minestuck.item.crafting.MSRecipeTypes; import com.mraof.minestuck.item.loot.MSLootTables; import com.mraof.minestuck.player.KindAbstratusList; -import com.mraof.minestuck.util.DispenserBehaviourUtil; import com.mraof.minestuck.util.MSAttachments; import com.mraof.minestuck.util.MSParticleType; import com.mraof.minestuck.util.MSSoundEvents; @@ -135,7 +135,7 @@ private void mainThreadSetup() KindAbstratusList.registerTypes(); DeployList.registerItems(); - DispenserBehaviourUtil.registerBehaviours(); + MSDispenserBehaviours.registerBehaviours(); ProgramData.init(); diff --git a/src/main/java/com/mraof/minestuck/alchemy/GristHelper.java b/src/main/java/com/mraof/minestuck/alchemy/GristHelper.java index 68fb233bd0..d9c60018db 100644 --- a/src/main/java/com/mraof/minestuck/alchemy/GristHelper.java +++ b/src/main/java/com/mraof/minestuck/alchemy/GristHelper.java @@ -8,16 +8,32 @@ import com.mraof.minestuck.event.GristDropsEvent; import com.mraof.minestuck.player.PlayerIdentifier; import net.minecraft.core.Holder; +import net.minecraft.nbt.NbtOps; +import net.minecraft.nbt.Tag; import net.minecraft.util.RandomSource; import net.minecraft.util.random.WeightedEntry; import net.minecraft.util.random.WeightedRandom; import net.neoforged.neoforge.common.NeoForge; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.List; import java.util.Map; +import java.util.Optional; -public class GristHelper +public final class GristHelper { + private static final Logger LOGGER = LogManager.getLogger(); + + public static Tag encodeGristType(GristType gristType) + { + return GristTypes.REGISTRY.byNameCodec().encodeStart(NbtOps.INSTANCE, gristType).getOrThrow(false, LOGGER::error); + } + + public static Optional parseGristType(Tag tag) + { + return GristTypes.REGISTRY.byNameCodec().parse(NbtOps.INSTANCE, tag).resultOrPartial(LOGGER::error); + } /** * An enum for indicating where the grist notifications comes from. @@ -72,4 +88,4 @@ public static MutableGristSet generateUnderlingGristDrops(UnderlingEntity entity return event.getNewDrops(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/api/alchemy/GristType.java b/src/main/java/com/mraof/minestuck/api/alchemy/GristType.java index d0bcfa2972..cbf7ad351e 100644 --- a/src/main/java/com/mraof/minestuck/api/alchemy/GristType.java +++ b/src/main/java/com/mraof/minestuck/api/alchemy/GristType.java @@ -1,7 +1,7 @@ package com.mraof.minestuck.api.alchemy; +import com.google.common.base.Suppliers; import com.mraof.minestuck.Minestuck; -import com.mraof.minestuck.util.LazyInstance; import net.minecraft.Util; import net.minecraft.core.HolderSet; import net.minecraft.network.chat.Component; @@ -33,8 +33,8 @@ public final class GristType implements Comparable @Nullable private final ResourceLocation textureOverrideId; - private final LazyInstance translationKey = new LazyInstance<>(() -> Util.makeDescriptionId("grist", GristType.this.getId())); - private final LazyInstance icon = new LazyInstance<>(() -> makeIconPath(GristType.this.getTextureId())); + private final Supplier translationKey = Suppliers.memoize(() -> Util.makeDescriptionId("grist", GristType.this.getId())); + private final Supplier icon = Suppliers.memoize(() -> makeIconPath(GristType.this.getTextureId())); public GristType(Properties properties) { @@ -213,4 +213,4 @@ private static ResourceLocation makeIconPath(ResourceLocation textureId) private record UnderlingData(int color, float power) {} -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/block/CassettePlayerBlock.java b/src/main/java/com/mraof/minestuck/block/CassettePlayerBlock.java index c3f941e49e..d594d91147 100644 --- a/src/main/java/com/mraof/minestuck/block/CassettePlayerBlock.java +++ b/src/main/java/com/mraof/minestuck/block/CassettePlayerBlock.java @@ -1,8 +1,7 @@ package com.mraof.minestuck.block; -import com.mraof.minestuck.item.CassetteItem; import com.mraof.minestuck.blockentity.CassettePlayerBlockEntity; -import com.mraof.minestuck.util.CustomVoxelShape; +import com.mraof.minestuck.item.CassetteItem; import net.minecraft.core.BlockPos; import net.minecraft.stats.Stats; import net.minecraft.world.InteractionHand; diff --git a/src/main/java/com/mraof/minestuck/block/CustomShapeBlock.java b/src/main/java/com/mraof/minestuck/block/CustomShapeBlock.java index c0305a8b8e..9bb8363fbc 100644 --- a/src/main/java/com/mraof/minestuck/block/CustomShapeBlock.java +++ b/src/main/java/com/mraof/minestuck/block/CustomShapeBlock.java @@ -1,6 +1,5 @@ package com.mraof.minestuck.block; -import com.mraof.minestuck.util.CustomVoxelShape; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.context.BlockPlaceContext; @@ -88,4 +87,4 @@ public FluidState getFluidState(BlockState state) { return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/util/CustomVoxelShape.java b/src/main/java/com/mraof/minestuck/block/CustomVoxelShape.java similarity index 98% rename from src/main/java/com/mraof/minestuck/util/CustomVoxelShape.java rename to src/main/java/com/mraof/minestuck/block/CustomVoxelShape.java index b182fce1da..bb975e80c8 100644 --- a/src/main/java/com/mraof/minestuck/util/CustomVoxelShape.java +++ b/src/main/java/com/mraof/minestuck/block/CustomVoxelShape.java @@ -1,4 +1,4 @@ -package com.mraof.minestuck.util; +package com.mraof.minestuck.block; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; diff --git a/src/main/java/com/mraof/minestuck/block/DirectionalCustomShapeBlock.java b/src/main/java/com/mraof/minestuck/block/DirectionalCustomShapeBlock.java index a04ae7ca45..47e8f5fb7c 100644 --- a/src/main/java/com/mraof/minestuck/block/DirectionalCustomShapeBlock.java +++ b/src/main/java/com/mraof/minestuck/block/DirectionalCustomShapeBlock.java @@ -1,7 +1,6 @@ package com.mraof.minestuck.block; import com.google.common.collect.ImmutableMap; -import com.mraof.minestuck.util.CustomVoxelShape; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.item.context.BlockPlaceContext; @@ -89,4 +88,4 @@ public FluidState getFluidState(BlockState state) { return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/block/LotusTimeCapsuleBlock.java b/src/main/java/com/mraof/minestuck/block/LotusTimeCapsuleBlock.java index 46c1c08e16..6c98f340b4 100644 --- a/src/main/java/com/mraof/minestuck/block/LotusTimeCapsuleBlock.java +++ b/src/main/java/com/mraof/minestuck/block/LotusTimeCapsuleBlock.java @@ -1,7 +1,6 @@ package com.mraof.minestuck.block; import com.mraof.minestuck.block.machine.MultiMachineBlock; -import com.mraof.minestuck.util.CustomVoxelShape; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -47,4 +46,4 @@ public BlockState mirror(BlockState state, Mirror mirror) } return state; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/block/MSBlockShapes.java b/src/main/java/com/mraof/minestuck/block/MSBlockShapes.java index 7ca55e68b2..309b16a0c6 100644 --- a/src/main/java/com/mraof/minestuck/block/MSBlockShapes.java +++ b/src/main/java/com/mraof/minestuck/block/MSBlockShapes.java @@ -1,6 +1,5 @@ package com.mraof.minestuck.block; -import com.mraof.minestuck.util.CustomVoxelShape; import net.minecraft.core.Direction; public class MSBlockShapes diff --git a/src/main/java/com/mraof/minestuck/block/MSBlocks.java b/src/main/java/com/mraof/minestuck/block/MSBlocks.java index 504fd6c8cd..1ef2fd2e73 100644 --- a/src/main/java/com/mraof/minestuck/block/MSBlocks.java +++ b/src/main/java/com/mraof/minestuck/block/MSBlocks.java @@ -10,7 +10,6 @@ import com.mraof.minestuck.computer.theme.MSComputerThemes; import com.mraof.minestuck.fluid.MSFluids; import com.mraof.minestuck.item.MSItems; -import com.mraof.minestuck.util.CustomVoxelShape; import com.mraof.minestuck.world.gen.feature.MSCFeatures; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; diff --git a/src/main/java/com/mraof/minestuck/block/SpikeBlock.java b/src/main/java/com/mraof/minestuck/block/SpikeBlock.java index 692be9cf34..5832bef08a 100644 --- a/src/main/java/com/mraof/minestuck/block/SpikeBlock.java +++ b/src/main/java/com/mraof/minestuck/block/SpikeBlock.java @@ -1,6 +1,5 @@ package com.mraof.minestuck.block; -import com.mraof.minestuck.util.CustomVoxelShape; import com.mraof.minestuck.util.MSDamageSources; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.Entity; diff --git a/src/main/java/com/mraof/minestuck/block/machine/AlchemiterBlock.java b/src/main/java/com/mraof/minestuck/block/machine/AlchemiterBlock.java index a8843df4a7..eb31a4f342 100644 --- a/src/main/java/com/mraof/minestuck/block/machine/AlchemiterBlock.java +++ b/src/main/java/com/mraof/minestuck/block/machine/AlchemiterBlock.java @@ -1,9 +1,9 @@ package com.mraof.minestuck.block.machine; +import com.mraof.minestuck.block.CustomVoxelShape; import com.mraof.minestuck.block.EnumDowelType; import com.mraof.minestuck.block.MSProperties; import com.mraof.minestuck.blockentity.machine.AlchemiterBlockEntity; -import com.mraof.minestuck.util.CustomVoxelShape; import com.mraof.minestuck.util.MSRotationUtil; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; @@ -165,4 +165,4 @@ protected void createBlockStateDefinition(StateDefinition.Builder, V> Map createEnumMapping(Class c, K[] } return Maps.immutableEnumMap(map); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/block/machine/PunchDesignixBlock.java b/src/main/java/com/mraof/minestuck/block/machine/PunchDesignixBlock.java index 06d6b4332a..c2c1f42191 100644 --- a/src/main/java/com/mraof/minestuck/block/machine/PunchDesignixBlock.java +++ b/src/main/java/com/mraof/minestuck/block/machine/PunchDesignixBlock.java @@ -1,8 +1,8 @@ package com.mraof.minestuck.block.machine; +import com.mraof.minestuck.block.CustomVoxelShape; import com.mraof.minestuck.block.MSProperties; import com.mraof.minestuck.blockentity.machine.PunchDesignixBlockEntity; -import com.mraof.minestuck.util.CustomVoxelShape; import com.mraof.minestuck.util.MSRotationUtil; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; @@ -128,4 +128,4 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) return new PunchDesignixBlockEntity(pos, state); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/block/machine/TotemLatheBlock.java b/src/main/java/com/mraof/minestuck/block/machine/TotemLatheBlock.java index dcb0019b4f..41feaedc19 100644 --- a/src/main/java/com/mraof/minestuck/block/machine/TotemLatheBlock.java +++ b/src/main/java/com/mraof/minestuck/block/machine/TotemLatheBlock.java @@ -1,13 +1,13 @@ package com.mraof.minestuck.block.machine; import com.mraof.minestuck.block.BlockUtil; +import com.mraof.minestuck.block.CustomVoxelShape; import com.mraof.minestuck.block.EnumDowelType; import com.mraof.minestuck.block.MSProperties; import com.mraof.minestuck.blockentity.ItemStackBlockEntity; import com.mraof.minestuck.blockentity.MSBlockEntityTypes; import com.mraof.minestuck.blockentity.machine.TotemLatheBlockEntity; import com.mraof.minestuck.blockentity.machine.TotemLatheDowelBlockEntity; -import com.mraof.minestuck.util.CustomVoxelShape; import com.mraof.minestuck.util.MSRotationUtil; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.BlockPos; @@ -227,4 +227,4 @@ public void onRemove(BlockState state, Level level, BlockPos pos, BlockState new super.onRemove(state, level, pos, newState, isMoving); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/block/redstone/ItemMagnetBlock.java b/src/main/java/com/mraof/minestuck/block/redstone/ItemMagnetBlock.java index d951ad2beb..f365a81988 100644 --- a/src/main/java/com/mraof/minestuck/block/redstone/ItemMagnetBlock.java +++ b/src/main/java/com/mraof/minestuck/block/redstone/ItemMagnetBlock.java @@ -1,12 +1,12 @@ package com.mraof.minestuck.block.redstone; import com.mraof.minestuck.block.BlockUtil; +import com.mraof.minestuck.block.CustomVoxelShape; import com.mraof.minestuck.block.DirectionalCustomShapeBlock; import com.mraof.minestuck.block.MSProperties; import com.mraof.minestuck.blockentity.MSBlockEntityTypes; import com.mraof.minestuck.blockentity.redstone.ItemMagnetBlockEntity; import com.mraof.minestuck.effects.CreativeShockEffect; -import com.mraof.minestuck.util.CustomVoxelShape; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.particles.DustParticleOptions; @@ -121,4 +121,4 @@ protected void createBlockStateDefinition(StateDefinition.Builder PlayState scanAnimation(Animatio state.getController().forceAnimationReset(); return PlayState.STOP; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/blockentity/machine/MiniAlchemiterBlockEntity.java b/src/main/java/com/mraof/minestuck/blockentity/machine/MiniAlchemiterBlockEntity.java index 13709eae87..855907d79a 100644 --- a/src/main/java/com/mraof/minestuck/blockentity/machine/MiniAlchemiterBlockEntity.java +++ b/src/main/java/com/mraof/minestuck/blockentity/machine/MiniAlchemiterBlockEntity.java @@ -13,7 +13,6 @@ import com.mraof.minestuck.player.GristCache; import com.mraof.minestuck.player.IdentifierHandler; import com.mraof.minestuck.player.PlayerIdentifier; -import com.mraof.minestuck.util.MSNBTUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -146,7 +145,7 @@ public void load(CompoundTag nbt) this.progressTracker.load(nbt); - this.wildcardGrist = MSNBTUtil.readGristType(nbt, "gristType"); + this.wildcardGrist = GristHelper.parseGristType(nbt.get("gristType")).orElseGet(GristTypes.BUILD); owner = IdentifierHandler.load(nbt, "owner").result().orElse(null); } @@ -158,7 +157,7 @@ public void saveAdditional(CompoundTag compound) this.progressTracker.save(compound); - MSNBTUtil.writeGristType(compound, "gristType", wildcardGrist); + compound.put("gristType", GristHelper.encodeGristType(wildcardGrist)); if(owner != null) owner.saveToNBT(compound, "owner"); @@ -256,4 +255,4 @@ public PlayerIdentifier getOwner() { return owner; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/blockentity/machine/PunchDesignixBlockEntity.java b/src/main/java/com/mraof/minestuck/blockentity/machine/PunchDesignixBlockEntity.java index 7107c9a46f..0479855416 100644 --- a/src/main/java/com/mraof/minestuck/blockentity/machine/PunchDesignixBlockEntity.java +++ b/src/main/java/com/mraof/minestuck/blockentity/machine/PunchDesignixBlockEntity.java @@ -11,7 +11,6 @@ import com.mraof.minestuck.blockentity.MSBlockEntityTypes; import com.mraof.minestuck.client.gui.MSScreenFactories; import com.mraof.minestuck.item.MSItems; -import com.mraof.minestuck.util.WorldEventUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -26,6 +25,7 @@ import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.LevelEvent; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import org.apache.logging.log4j.LogManager; @@ -191,7 +191,16 @@ public void punchCard(ServerPlayer player) private void effects(boolean success) { - WorldEventUtil.dispenserEffect(getLevel(), getBlockPos(), getBlockState().getValue(FACING), success); + if(this.level == null) + return; + + this.level.levelEvent(success ? LevelEvent.SOUND_DISPENSER_DISPENSE : LevelEvent.SOUND_DISPENSER_FAIL, this.worldPosition, 0); + if(success) + { + Direction direction = getBlockState().getValue(FACING); + int i = direction.getStepX() + 1 + (direction.getStepZ() + 1) * 3; + this.level.levelEvent(LevelEvent.PARTICLES_SHOOT_SMOKE, this.worldPosition, i); + } } private boolean isUsable(BlockState state) @@ -261,4 +270,4 @@ public Packet getUpdatePacket() { return ClientboundBlockEntityDataPacket.create(this); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/blockentity/machine/TotemLatheBlockEntity.java b/src/main/java/com/mraof/minestuck/blockentity/machine/TotemLatheBlockEntity.java index fcd22bd6ea..4df6513f7d 100644 --- a/src/main/java/com/mraof/minestuck/blockentity/machine/TotemLatheBlockEntity.java +++ b/src/main/java/com/mraof/minestuck/blockentity/machine/TotemLatheBlockEntity.java @@ -1,18 +1,17 @@ package com.mraof.minestuck.blockentity.machine; +import com.mraof.minestuck.alchemy.AlchemyHelper; +import com.mraof.minestuck.api.alchemy.recipe.combination.CombinationMode; import com.mraof.minestuck.api.alchemy.recipe.combination.CombinationRecipe; import com.mraof.minestuck.api.alchemy.recipe.combination.CombinerContainer; import com.mraof.minestuck.block.EnumDowelType; import com.mraof.minestuck.block.MSBlocks; import com.mraof.minestuck.block.machine.TotemLatheBlock; +import com.mraof.minestuck.blockentity.ItemStackBlockEntity; import com.mraof.minestuck.blockentity.MSBlockEntityTypes; import com.mraof.minestuck.item.MSItems; -import com.mraof.minestuck.alchemy.AlchemyHelper; -import com.mraof.minestuck.api.alchemy.recipe.combination.CombinationMode; -import com.mraof.minestuck.blockentity.ItemStackBlockEntity; import com.mraof.minestuck.util.ColorHandler; import com.mraof.minestuck.util.MSSoundEvents; -import com.mraof.minestuck.util.WorldEventUtil; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; @@ -430,14 +429,8 @@ public Packet getUpdatePacket() return ClientboundBlockEntityDataPacket.create(this); } - private void effects(boolean success) - { - BlockPos pos = getBlockPos().above().relative(getFacing().getCounterClockWise(), 2); - WorldEventUtil.dispenserEffect(getLevel(), pos, getFacing(), success); - } - public boolean isProcessing() { return isProcessing; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/data/BoondollarPricingProvider.java b/src/main/java/com/mraof/minestuck/data/BoondollarPriceProvider.java similarity index 87% rename from src/main/java/com/mraof/minestuck/data/BoondollarPricingProvider.java rename to src/main/java/com/mraof/minestuck/data/BoondollarPriceProvider.java index b14c99999d..ea0b906876 100644 --- a/src/main/java/com/mraof/minestuck/data/BoondollarPricingProvider.java +++ b/src/main/java/com/mraof/minestuck/data/BoondollarPriceProvider.java @@ -1,8 +1,9 @@ package com.mraof.minestuck.data; +import com.google.gson.JsonElement; +import com.mojang.serialization.JsonOps; +import com.mraof.minestuck.entity.consort.BoondollarPriceRecipe; import com.mraof.minestuck.item.MSItems; -import com.mraof.minestuck.util.BoondollarPriceManager; -import com.mraof.minestuck.util.BoondollarPricing; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.data.CachedOutput; @@ -14,6 +15,8 @@ import net.minecraft.util.valueproviders.UniformInt; import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.level.ItemLike; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import javax.annotation.ParametersAreNonnullByDefault; import java.nio.file.Path; @@ -25,19 +28,21 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -public class BoondollarPricingProvider implements DataProvider +public class BoondollarPriceProvider implements DataProvider { - private final Map pricings = new HashMap<>(); + private static final Logger LOGGER = LogManager.getLogger(); + + private final Map recipes = new HashMap<>(); private final PackOutput output; private final String modid; - public BoondollarPricingProvider(PackOutput output, String modid) + public BoondollarPriceProvider(PackOutput output, String modid) { this.output = output; this.modid = modid; } - protected void registerPricings() + protected void registerPrices() { add(ONION.get(), 9, 15); add(JAR_OF_BUGS.get(), 12, 18); @@ -250,26 +255,28 @@ protected void add(ItemLike item, int min, int max) protected void add(Ingredient ingredient, IntProvider range, String name) { - add(new BoondollarPricing(ingredient, range), new ResourceLocation(modid, name)); + add(new BoondollarPriceRecipe(ingredient, range), new ResourceLocation(modid, name)); } - protected void add(BoondollarPricing pricing, ResourceLocation name) + protected void add(BoondollarPriceRecipe pricing, ResourceLocation name) { - pricings.put(name, pricing); + recipes.put(name, pricing); } @Override public CompletableFuture run(CachedOutput cache) { - registerPricings(); + registerPrices(); Path outputPath = output.getOutputFolder(); - List> futures = new ArrayList<>(pricings.size()); + List> futures = new ArrayList<>(recipes.size()); - for(Map.Entry entry : pricings.entrySet()) + for(Map.Entry entry : recipes.entrySet()) { Path pricingPath = getPath(outputPath, entry.getKey()); - futures.add(DataProvider.saveStable(cache, BoondollarPriceManager.parsePrice(entry.getValue()), pricingPath)); + JsonElement jsonData = BoondollarPriceRecipe.CODEC.encodeStart(JsonOps.INSTANCE, entry.getValue()) + .getOrThrow(false, message -> LOGGER.error("Problem encoding boondollar price {}: {}", entry.getKey(), message)); + futures.add(DataProvider.saveStable(cache, jsonData, pricingPath)); } return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); } @@ -284,4 +291,4 @@ public String getName() { return "Boondollar pricings"; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/data/MinestuckData.java b/src/main/java/com/mraof/minestuck/data/MinestuckData.java index 04e68188a8..0e755b1c3e 100644 --- a/src/main/java/com/mraof/minestuck/data/MinestuckData.java +++ b/src/main/java/com/mraof/minestuck/data/MinestuckData.java @@ -52,7 +52,7 @@ public static void gatherData(GatherDataEvent event) gen.addProvider(event.includeServer(), new ComputerThemeProvider(output)); - gen.addProvider(event.includeServer(), new BoondollarPricingProvider(output, Minestuck.MOD_ID)); + gen.addProvider(event.includeServer(), new BoondollarPriceProvider(output, Minestuck.MOD_ID)); gen.addProvider(event.includeServer(), MinestuckLootTableProvider.create(output)); gen.addProvider(event.includeServer(), new MSLootModifiers(output)); gen.addProvider(event.includeServer(), MSAdvancementProvider.create(output, lookupProvider, fileHelper)); diff --git a/src/main/java/com/mraof/minestuck/data/recipe/MinestuckGristCostsProvider.java b/src/main/java/com/mraof/minestuck/data/recipe/MinestuckGristCostsProvider.java index ac787dfbef..5994a5fdae 100644 --- a/src/main/java/com/mraof/minestuck/data/recipe/MinestuckGristCostsProvider.java +++ b/src/main/java/com/mraof/minestuck/data/recipe/MinestuckGristCostsProvider.java @@ -37,7 +37,7 @@ public static void buildRecipes(RecipeOutput recipeSaver) SourceGristCostBuilder.of(Items.SUSPICIOUS_SAND).source(Items.SAND).grist(DIAMOND, 10).buildFor(recipeSaver, Minestuck.MOD_ID); SourceGristCostBuilder.of(Items.SUSPICIOUS_GRAVEL).source(Items.GRAVEL).grist(DIAMOND, 10).buildFor(recipeSaver, Minestuck.MOD_ID); GristCostRecipeBuilder.of(Items.GLASS).grist(BUILD, 1).buildFor(recipeSaver, Minestuck.MOD_ID); - SourceGristCostBuilder.of(ExtraForgeTags.Items.TERRACOTTA).source(Items.CLAY).buildFor(recipeSaver, Minestuck.MOD_ID); + SourceGristCostBuilder.of(ItemTags.TERRACOTTA).source(Items.CLAY).buildFor(recipeSaver, Minestuck.MOD_ID); GristCostRecipeBuilder.of(Items.CLAY_BALL).grist(SHALE, 1).grist(BUILD, 1).buildFor(recipeSaver, Minestuck.MOD_ID); GristCostRecipeBuilder.of(Items.FLINT).grist(BUILD, 4).buildFor(recipeSaver, Minestuck.MOD_ID); GristCostRecipeBuilder.of(Items.POINTED_DRIPSTONE).grist(BUILD, 4).grist(AMBER, 3).buildFor(recipeSaver, Minestuck.MOD_ID); @@ -980,4 +980,4 @@ public static void oreCost(TagKey ores, Item material, float multiplier, R { SourceGristCostBuilder.of(ores).source(material).multiplier(multiplier).grist(BUILD, 4).buildFor(recipeOutput, modId); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/data/tag/MinestuckBlockTagsProvider.java b/src/main/java/com/mraof/minestuck/data/tag/MinestuckBlockTagsProvider.java index 4ba42a7b29..1f8994e0b0 100644 --- a/src/main/java/com/mraof/minestuck/data/tag/MinestuckBlockTagsProvider.java +++ b/src/main/java/com/mraof/minestuck/data/tag/MinestuckBlockTagsProvider.java @@ -261,8 +261,6 @@ protected void addTags(HolderLookup.Provider provider) tag(ExtraForgeTags.Blocks.URANIUM_ORES).addTag(URANIUM_ORES); tag(ExtraForgeTags.Blocks.URANIUM_STORAGE_BLOCKS).add(URANIUM_BLOCK.get()); - tag(ExtraForgeTags.Blocks.TERRACOTTA).add(Blocks.TERRACOTTA, Blocks.BLACK_GLAZED_TERRACOTTA, Blocks.BLACK_TERRACOTTA, Blocks.BLUE_GLAZED_TERRACOTTA, Blocks.BLUE_TERRACOTTA, Blocks.BROWN_GLAZED_TERRACOTTA, Blocks.BROWN_TERRACOTTA, Blocks.CYAN_GLAZED_TERRACOTTA, Blocks.CYAN_TERRACOTTA, Blocks.GRAY_GLAZED_TERRACOTTA, Blocks.GRAY_TERRACOTTA, Blocks.GREEN_GLAZED_TERRACOTTA, Blocks.GREEN_TERRACOTTA, Blocks.LIGHT_BLUE_GLAZED_TERRACOTTA, Blocks.LIGHT_BLUE_TERRACOTTA, Blocks.LIGHT_GRAY_GLAZED_TERRACOTTA, Blocks.LIGHT_GRAY_TERRACOTTA, - Blocks.LIME_GLAZED_TERRACOTTA, Blocks.LIME_TERRACOTTA, Blocks.MAGENTA_GLAZED_TERRACOTTA, Blocks.MAGENTA_TERRACOTTA, Blocks.ORANGE_GLAZED_TERRACOTTA, Blocks.ORANGE_TERRACOTTA, Blocks.PINK_GLAZED_TERRACOTTA, Blocks.PINK_TERRACOTTA, Blocks.PURPLE_GLAZED_TERRACOTTA, Blocks.PURPLE_TERRACOTTA, Blocks.RED_GLAZED_TERRACOTTA, Blocks.RED_TERRACOTTA, Blocks.WHITE_GLAZED_TERRACOTTA, Blocks.WHITE_TERRACOTTA, Blocks.YELLOW_GLAZED_TERRACOTTA, Blocks.YELLOW_TERRACOTTA); tag(GREEN_HIEROGLYPHS).add(GREEN_STONE_BRICK_FROG.get(), GREEN_STONE_BRICK_LOTUS.get(), GREEN_STONE_BRICK_IGUANA_LEFT.get(), GREEN_STONE_BRICK_IGUANA_RIGHT.get(), GREEN_STONE_BRICK_NAK_LEFT.get(), GREEN_STONE_BRICK_NAK_RIGHT.get(), GREEN_STONE_BRICK_SALAMANDER_LEFT.get(), GREEN_STONE_BRICK_SALAMANDER_RIGHT.get(), GREEN_STONE_BRICK_SKAIA.get(), GREEN_STONE_BRICK_TURTLE.get()); tag(GLOWING_LOGS).add(GLOWING_LOG.get(), GLOWING_WOOD.get(), STRIPPED_GLOWING_LOG.get(), STRIPPED_GLOWING_WOOD.get()); diff --git a/src/main/java/com/mraof/minestuck/data/tag/MinestuckItemTagsProvider.java b/src/main/java/com/mraof/minestuck/data/tag/MinestuckItemTagsProvider.java index 8e3f4c7d06..27446167b7 100644 --- a/src/main/java/com/mraof/minestuck/data/tag/MinestuckItemTagsProvider.java +++ b/src/main/java/com/mraof/minestuck/data/tag/MinestuckItemTagsProvider.java @@ -69,7 +69,6 @@ protected void addTags(HolderLookup.Provider provider) copy(Tags.Blocks.STORAGE_BLOCKS, STORAGE_BLOCKS); copy(ExtraForgeTags.Blocks.URANIUM_ORES, ExtraForgeTags.Items.URANIUM_ORES); copy(ExtraForgeTags.Blocks.URANIUM_STORAGE_BLOCKS, ExtraForgeTags.Items.URANIUM_STORAGE_BLOCKS); - copy(ExtraForgeTags.Blocks.TERRACOTTA, ExtraForgeTags.Items.TERRACOTTA); copy(MSTags.Blocks.GLOWING_LOGS, GLOWING_LOGS); copy(MSTags.Blocks.FROST_LOGS, FROST_LOGS); copy(MSTags.Blocks.RAINBOW_LOGS, RAINBOW_LOGS); diff --git a/src/main/java/com/mraof/minestuck/entity/carapacian/PawnEntity.java b/src/main/java/com/mraof/minestuck/entity/carapacian/PawnEntity.java index b9238bcec3..2f433bb47e 100644 --- a/src/main/java/com/mraof/minestuck/entity/carapacian/PawnEntity.java +++ b/src/main/java/com/mraof/minestuck/entity/carapacian/PawnEntity.java @@ -9,7 +9,6 @@ import com.mraof.minestuck.entity.dialogue.DialogueEntity; import com.mraof.minestuck.entity.dialogue.RandomlySelectableDialogue; import com.mraof.minestuck.item.MSItems; -import com.mraof.minestuck.util.AnimationControllerUtil; import net.minecraft.ChatFormatting; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.syncher.EntityDataAccessor; @@ -40,10 +39,8 @@ import net.minecraft.world.level.ServerLevelAccessor; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; -import software.bernie.geckolib.core.animation.AnimatableManager; -import software.bernie.geckolib.core.animation.Animation; import software.bernie.geckolib.core.animation.AnimationState; -import software.bernie.geckolib.core.animation.RawAnimation; +import software.bernie.geckolib.core.animation.*; import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; @@ -343,11 +340,11 @@ public String getSpriteType() @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { - controllers.add(AnimationControllerUtil.createAnimation(this, "walkArmsAnimation", 1, PawnEntity::walkArmsAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "walkAnimation", 1, PawnEntity::walkAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "deathAnimation", 1, PawnEntity::deathAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "swingAnimation", 2, PawnEntity::swingAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "talkAnimation", 1, PawnEntity::talkAnimation)); + controllers.add(new AnimationController<>(this, "walkArmsAnimation", PawnEntity::walkArmsAnimation)); + controllers.add(new AnimationController<>(this, "walkAnimation", PawnEntity::walkAnimation)); + controllers.add(new AnimationController<>(this, "deathAnimation", PawnEntity::deathAnimation)); + controllers.add(new AnimationController<>(this, "swingAnimation", PawnEntity::swingAnimation).setAnimationSpeed(2)); + controllers.add(new AnimationController<>(this, "talkAnimation", PawnEntity::talkAnimation)); } private static PlayState walkAnimation(AnimationState state) @@ -402,4 +399,4 @@ private static PlayState talkAnimation(AnimationState state) return PlayState.STOP; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/entity/consort/BoondollarPriceRecipe.java b/src/main/java/com/mraof/minestuck/entity/consort/BoondollarPriceRecipe.java new file mode 100644 index 0000000000..5e50092380 --- /dev/null +++ b/src/main/java/com/mraof/minestuck/entity/consort/BoondollarPriceRecipe.java @@ -0,0 +1,26 @@ +package com.mraof.minestuck.entity.consort; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.util.RandomSource; +import net.minecraft.util.valueproviders.IntProvider; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; + +public record BoondollarPriceRecipe(Ingredient ingredient, IntProvider priceRange) +{ + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Ingredient.CODEC_NONEMPTY.fieldOf("ingredient").forGetter(BoondollarPriceRecipe::ingredient), + IntProvider.CODEC.fieldOf("range").forGetter(BoondollarPriceRecipe::priceRange) + ).apply(instance, BoondollarPriceRecipe::new)); + + public int generatePrice(RandomSource random) + { + return priceRange.sample(random); + } + + public boolean appliesTo(ItemStack stack) + { + return ingredient.test(stack); + } +} diff --git a/src/main/java/com/mraof/minestuck/entity/consort/BoondollarPrices.java b/src/main/java/com/mraof/minestuck/entity/consort/BoondollarPrices.java new file mode 100644 index 0000000000..d8e2f5e03d --- /dev/null +++ b/src/main/java/com/mraof/minestuck/entity/consort/BoondollarPrices.java @@ -0,0 +1,84 @@ +package com.mraof.minestuck.entity.consort; + +import com.google.common.collect.ImmutableList; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonElement; +import com.mojang.serialization.JsonOps; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.packs.resources.ResourceManager; +import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; +import net.minecraft.util.RandomSource; +import net.minecraft.util.profiling.ProfilerFiller; +import net.minecraft.world.item.ItemStack; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.neoforge.event.AddReloadListenerEvent; +import net.neoforged.neoforge.event.server.ServerStoppedEvent; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Optional; + + +@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) +public final class BoondollarPrices +{ + private final List prices; + + private BoondollarPrices(List prices) + { + this.prices = prices; + } + + public Optional findPrice(ItemStack stack, RandomSource rand) + { + return prices.stream().filter(pricing -> pricing.appliesTo(stack)).findAny().map(pricing -> pricing.generatePrice(rand)); + } + + private static BoondollarPrices INSTANCE; + + public static BoondollarPrices getInstance() + { + return Objects.requireNonNull(INSTANCE); + } + + @SubscribeEvent + private static void onResourceReload(AddReloadListenerEvent event) + { + event.addListener(new BoondollarPrices.Loader()); + } + + @SubscribeEvent + private static void onServerStopped(ServerStoppedEvent event) + { + INSTANCE = null; + } + + private static final class Loader extends SimpleJsonResourceReloadListener + { + private static final Logger LOGGER = LogManager.getLogger(); + + Loader() + { + super(new GsonBuilder().create(), "minestuck/boondollar_prices"); + } + + @Override + protected void apply(Map jsonEntries, ResourceManager resourceManager, ProfilerFiller profiler) + { + ImmutableList.Builder prices = ImmutableList.builder(); + for(Map.Entry entry : jsonEntries.entrySet()) + { + BoondollarPriceRecipe.CODEC.parse(JsonOps.INSTANCE, entry.getValue()) + .resultOrPartial(message -> LOGGER.error("Couldn't parse boondollar pricing {}: {}", entry.getKey(), message)) + .ifPresent(prices::add); + } + + INSTANCE = new BoondollarPrices(prices.build()); + LOGGER.info("Loaded {} boondollar prices", INSTANCE.prices.size()); + } + } +} diff --git a/src/main/java/com/mraof/minestuck/entity/consort/ConsortEntity.java b/src/main/java/com/mraof/minestuck/entity/consort/ConsortEntity.java index 7773229d99..99a6f8c84b 100644 --- a/src/main/java/com/mraof/minestuck/entity/consort/ConsortEntity.java +++ b/src/main/java/com/mraof/minestuck/entity/consort/ConsortEntity.java @@ -14,7 +14,6 @@ import com.mraof.minestuck.player.IdentifierHandler; import com.mraof.minestuck.player.PlayerData; import com.mraof.minestuck.player.PlayerIdentifier; -import com.mraof.minestuck.util.AnimationControllerUtil; import com.mraof.minestuck.world.MSDimensions; import net.minecraft.ChatFormatting; import net.minecraft.MethodsReturnNonnullByDefault; @@ -49,10 +48,8 @@ import org.slf4j.Logger; import software.bernie.geckolib.animatable.GeoEntity; import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache; -import software.bernie.geckolib.core.animation.AnimatableManager; -import software.bernie.geckolib.core.animation.Animation; import software.bernie.geckolib.core.animation.AnimationState; -import software.bernie.geckolib.core.animation.RawAnimation; +import software.bernie.geckolib.core.animation.*; import software.bernie.geckolib.core.object.PlayState; import software.bernie.geckolib.util.GeckoLibUtil; @@ -444,11 +441,11 @@ public String getSpriteType() @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { - controllers.add(AnimationControllerUtil.createAnimation(this, "idleAnimation", 1, ConsortEntity::idleAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "walkAnimation", 1, ConsortEntity::walkAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "armsAnimation", 1, ConsortEntity::armsAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "deathAnimation", 1, ConsortEntity::deathAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "actionAnimation", 1, ConsortEntity::actionAnimation)); + controllers.add(new AnimationController<>(this, "idleAnimation", ConsortEntity::idleAnimation)); + controllers.add(new AnimationController<>(this, "walkAnimation", ConsortEntity::walkAnimation)); + controllers.add(new AnimationController<>(this, "armsAnimation", ConsortEntity::armsAnimation)); + controllers.add(new AnimationController<>(this, "deathAnimation", ConsortEntity::deathAnimation)); + controllers.add(new AnimationController<>(this, "actionAnimation", ConsortEntity::actionAnimation)); } private static PlayState idleAnimation(AnimationState state) @@ -522,4 +519,5 @@ private static PlayState actionAnimation(AnimationState state) return PlayState.STOP; } -} \ No newline at end of file +} + diff --git a/src/main/java/com/mraof/minestuck/entity/consort/ConsortRewardHandler.java b/src/main/java/com/mraof/minestuck/entity/consort/ConsortRewardHandler.java index 9462ce452e..a0ff161990 100644 --- a/src/main/java/com/mraof/minestuck/entity/consort/ConsortRewardHandler.java +++ b/src/main/java/com/mraof/minestuck/entity/consort/ConsortRewardHandler.java @@ -1,6 +1,5 @@ package com.mraof.minestuck.entity.consort; -import com.mraof.minestuck.util.BoondollarPriceManager; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.RandomSource; @@ -40,7 +39,7 @@ public static List> generateStock(ResourceLocation loot } } - Optional price = BoondollarPriceManager.getInstance().findPrice(stack, rand); + Optional price = BoondollarPrices.getInstance().findPrice(stack, rand); if (price.isPresent() && itemPriceList.size() < 9) itemPriceList.add(Pair.of(stack, price.get())); if (!price.isPresent()) @@ -48,4 +47,4 @@ public static List> generateStock(ResourceLocation loot } return itemPriceList; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/entity/dialogue/Dialogue.java b/src/main/java/com/mraof/minestuck/entity/dialogue/Dialogue.java index 47af864985..ab2b77d236 100644 --- a/src/main/java/com/mraof/minestuck/entity/dialogue/Dialogue.java +++ b/src/main/java/com/mraof/minestuck/entity/dialogue/Dialogue.java @@ -7,7 +7,6 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mraof.minestuck.Minestuck; import com.mraof.minestuck.entity.dialogue.condition.Condition; -import com.mraof.minestuck.util.PreservingOptionalFieldCodec; import net.minecraft.ChatFormatting; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.network.FriendlyByteBuf; @@ -15,10 +14,12 @@ import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.ExtraCodecs; import net.minecraft.util.StringRepresentable; import net.minecraft.world.entity.LivingEntity; import javax.annotation.Nullable; +import java.util.Collections; import java.util.List; import java.util.Locale; import java.util.Optional; @@ -92,9 +93,9 @@ public record Node(List> messages, DialogueAn messages -> messages.size() == 1 && messages.get(0).getFirst() == MessageType.ENTITY ? Either.left(messages.get(0).getSecond()): Either.right(messages)); public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( MESSAGES_MAP_CODEC.forGetter(Node::messages), - PreservingOptionalFieldCodec.withDefault(DialogueAnimationData.CODEC, "animation", DialogueAnimationData.DEFAULT_ANIMATION).forGetter(Node::animation), - PreservingOptionalFieldCodec.withDefault(ResourceLocation.CODEC, "gui", DEFAULT_GUI).forGetter(Node::guiPath), - PreservingOptionalFieldCodec.forList(Response.LIST_CODEC, "responses").forGetter(Node::responses) + ExtraCodecs.strictOptionalField(DialogueAnimationData.CODEC, "animation", DialogueAnimationData.DEFAULT_ANIMATION).forGetter(Node::animation), + ExtraCodecs.strictOptionalField(ResourceLocation.CODEC, "gui", DEFAULT_GUI).forGetter(Node::guiPath), + ExtraCodecs.strictOptionalField(Response.LIST_CODEC, "responses", Collections.emptyList()).forGetter(Node::responses) ).apply(instance, Node::new)); DialogueData evaluateData(LivingEntity entity, ServerPlayer player, @Nullable Dialogue.NextDialogue source) @@ -171,11 +172,11 @@ public record Response(DialogueMessage message, List triggers, Optional { public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( DialogueMessage.CODEC.fieldOf("message").forGetter(Response::message), - PreservingOptionalFieldCodec.withDefault(Trigger.LIST_CODEC, "triggers", List.of()).forGetter(Response::triggers), - new PreservingOptionalFieldCodec<>(NextDialogue.EITHER_CODEC, "next_dialogue").forGetter(Response::nextDialogue), - PreservingOptionalFieldCodec.withDefault(Condition.CODEC, "condition", Condition.AlwaysTrue.INSTANCE).forGetter(Response::condition), - PreservingOptionalFieldCodec.withDefault(Codec.BOOL, "hide_if_failed", true).forGetter(Response::hideIfFailed), - new PreservingOptionalFieldCodec<>(Codec.STRING, "fail_tooltip").forGetter(Response::failTooltipKey) + ExtraCodecs.strictOptionalField(Trigger.LIST_CODEC, "triggers", List.of()).forGetter(Response::triggers), + ExtraCodecs.strictOptionalField(NextDialogue.EITHER_CODEC, "next_dialogue").forGetter(Response::nextDialogue), + ExtraCodecs.strictOptionalField(Condition.CODEC, "condition", Condition.AlwaysTrue.INSTANCE).forGetter(Response::condition), + ExtraCodecs.strictOptionalField(Codec.BOOL, "hide_if_failed", true).forGetter(Response::hideIfFailed), + ExtraCodecs.strictOptionalField(Codec.STRING, "fail_tooltip").forGetter(Response::failTooltipKey) ).apply(instance, Response::new)); static Codec> LIST_CODEC = Response.CODEC.listOf(); @@ -238,8 +239,8 @@ public record SelectableDialogue(ResourceLocation dialogueId, Condition conditio public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( ResourceLocation.CODEC.fieldOf("dialogue").forGetter(SelectableDialogue::dialogueId), Condition.NPC_ONLY_CODEC.fieldOf("condition").forGetter(SelectableDialogue::condition), - PreservingOptionalFieldCodec.withDefault(Codec.INT, "dialogue_weight", DEFAULT_WEIGHT).forGetter(SelectableDialogue::weight), - PreservingOptionalFieldCodec.withDefault(Codec.BOOL, "keep_on_reset", false).forGetter(SelectableDialogue::keepOnReset) + ExtraCodecs.strictOptionalField(Codec.INT, "dialogue_weight", DEFAULT_WEIGHT).forGetter(SelectableDialogue::weight), + ExtraCodecs.strictOptionalField(Codec.BOOL, "keep_on_reset", false).forGetter(SelectableDialogue::keepOnReset) ).apply(instance, SelectableDialogue::new)); } diff --git a/src/main/java/com/mraof/minestuck/entity/dialogue/DialogueAnimationData.java b/src/main/java/com/mraof/minestuck/entity/dialogue/DialogueAnimationData.java index 2d58e50115..6074acce28 100644 --- a/src/main/java/com/mraof/minestuck/entity/dialogue/DialogueAnimationData.java +++ b/src/main/java/com/mraof/minestuck/entity/dialogue/DialogueAnimationData.java @@ -3,12 +3,12 @@ import com.mojang.serialization.Codec; import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mraof.minestuck.Minestuck; -import com.mraof.minestuck.util.PreservingOptionalFieldCodec; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.AbstractTexture; import net.minecraft.client.renderer.texture.MissingTextureAtlasSprite; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.resources.ResourceLocation; +import net.minecraft.util.ExtraCodecs; public record DialogueAnimationData(String emotion, int spriteHeight, int spriteWidth, int xOffset, int yOffset, float scale) { @@ -23,12 +23,12 @@ public record DialogueAnimationData(String emotion, int spriteHeight, int sprite public static final DialogueAnimationData DEFAULT_ANIMATION = new DialogueAnimationData(GENERIC_EMOTION, DEFAULT_SPRITE_HEIGHT, DEFAULT_SPRITE_WIDTH, 0, 0, 1.0F); public static Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - PreservingOptionalFieldCodec.withDefault(Codec.STRING, "emotion", GENERIC_EMOTION).forGetter(DialogueAnimationData::emotion), - PreservingOptionalFieldCodec.withDefault(Codec.INT, "height", DEFAULT_SPRITE_HEIGHT).forGetter(DialogueAnimationData::spriteHeight), - PreservingOptionalFieldCodec.withDefault(Codec.INT, "width", DEFAULT_SPRITE_WIDTH).forGetter(DialogueAnimationData::spriteWidth), - PreservingOptionalFieldCodec.withDefault(Codec.INT, "x_offset", 0).forGetter(DialogueAnimationData::xOffset), - PreservingOptionalFieldCodec.withDefault(Codec.INT, "y_offset", 0).forGetter(DialogueAnimationData::yOffset), - PreservingOptionalFieldCodec.withDefault(Codec.FLOAT, "scale", 1.0F).forGetter(DialogueAnimationData::scale) + ExtraCodecs.strictOptionalField(Codec.STRING, "emotion", GENERIC_EMOTION).forGetter(DialogueAnimationData::emotion), + ExtraCodecs.strictOptionalField(Codec.INT, "height", DEFAULT_SPRITE_HEIGHT).forGetter(DialogueAnimationData::spriteHeight), + ExtraCodecs.strictOptionalField(Codec.INT, "width", DEFAULT_SPRITE_WIDTH).forGetter(DialogueAnimationData::spriteWidth), + ExtraCodecs.strictOptionalField(Codec.INT, "x_offset", 0).forGetter(DialogueAnimationData::xOffset), + ExtraCodecs.strictOptionalField(Codec.INT, "y_offset", 0).forGetter(DialogueAnimationData::yOffset), + ExtraCodecs.strictOptionalField(Codec.FLOAT, "scale", 1.0F).forGetter(DialogueAnimationData::scale) ).apply(instance, DialogueAnimationData::new)); public static DialogueAnimationData read(FriendlyByteBuf buffer) @@ -71,4 +71,4 @@ public ResourceLocation getRenderPath(String spriteType) return spritePath; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/entity/dialogue/Trigger.java b/src/main/java/com/mraof/minestuck/entity/dialogue/Trigger.java index 40a1ae8f45..d550cf95a8 100644 --- a/src/main/java/com/mraof/minestuck/entity/dialogue/Trigger.java +++ b/src/main/java/com/mraof/minestuck/entity/dialogue/Trigger.java @@ -11,7 +11,6 @@ import com.mraof.minestuck.inventory.ConsortMerchantInventory; import com.mraof.minestuck.player.PlayerBoondollars; import com.mraof.minestuck.player.PlayerData; -import com.mraof.minestuck.util.PreservingOptionalFieldCodec; import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.Util; import net.minecraft.commands.CommandSourceStack; @@ -21,6 +20,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.ExtraCodecs; import net.minecraft.world.SimpleMenuProvider; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; @@ -166,7 +166,7 @@ record TakeItem(Item item, int amount) implements Trigger { static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(TakeItem::item), - PreservingOptionalFieldCodec.withDefault(Codec.INT, "amount", 1).forGetter(TakeItem::amount) + ExtraCodecs.strictOptionalField(Codec.INT, "amount", 1).forGetter(TakeItem::amount) ).apply(instance, TakeItem::new)); public TakeItem(Item item) @@ -239,7 +239,7 @@ record SetNPCItem(Item item, EquipmentSlot slot) implements Trigger { static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(SetNPCItem::item), - PreservingOptionalFieldCodec.withDefault(EQUIPMENT_CODEC, "slot", EquipmentSlot.MAINHAND).forGetter(SetNPCItem::slot) + ExtraCodecs.strictOptionalField(EQUIPMENT_CODEC, "slot", EquipmentSlot.MAINHAND).forGetter(SetNPCItem::slot) ).apply(instance, SetNPCItem::new)); @Override @@ -261,7 +261,7 @@ public void triggerEffect(LivingEntity entity, ServerPlayer player) record SetNPCMatchedItem(EquipmentSlot slot) implements Trigger { static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - PreservingOptionalFieldCodec.withDefault(EQUIPMENT_CODEC, "slot", EquipmentSlot.MAINHAND).forGetter(SetNPCMatchedItem::slot) + ExtraCodecs.strictOptionalField(EQUIPMENT_CODEC, "slot", EquipmentSlot.MAINHAND).forGetter(SetNPCMatchedItem::slot) ).apply(instance, SetNPCMatchedItem::new)); @Override @@ -290,7 +290,7 @@ record GiveItem(Item item, int amount) implements Trigger { static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(GiveItem::item), - PreservingOptionalFieldCodec.withDefault(Codec.INT, "amount", 1).forGetter(GiveItem::amount) + ExtraCodecs.strictOptionalField(Codec.INT, "amount", 1).forGetter(GiveItem::amount) ).apply(instance, GiveItem::new)); public GiveItem(Item item) diff --git a/src/main/java/com/mraof/minestuck/entity/dialogue/condition/Condition.java b/src/main/java/com/mraof/minestuck/entity/dialogue/condition/Condition.java index 070b933c2d..7987a49c1f 100644 --- a/src/main/java/com/mraof/minestuck/entity/dialogue/condition/Condition.java +++ b/src/main/java/com/mraof/minestuck/entity/dialogue/condition/Condition.java @@ -12,7 +12,6 @@ import com.mraof.minestuck.entity.dialogue.DialogueEntity; import com.mraof.minestuck.player.*; import com.mraof.minestuck.skaianet.SburbPlayerData; -import com.mraof.minestuck.util.PreservingOptionalFieldCodec; import com.mraof.minestuck.world.MSDimensions; import com.mraof.minestuck.world.lands.LandTypePair; import com.mraof.minestuck.world.lands.LandTypes; @@ -512,7 +511,7 @@ record PlayerHasItem(Item item, int amount) implements Condition { static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( BuiltInRegistries.ITEM.byNameCodec().fieldOf("item").forGetter(PlayerHasItem::item), - PreservingOptionalFieldCodec.withDefault(Codec.INT, "amount", 1).forGetter(PlayerHasItem::amount) + ExtraCodecs.strictOptionalField(Codec.INT, "amount", 1).forGetter(PlayerHasItem::amount) ).apply(instance, PlayerHasItem::new)); @Override @@ -717,8 +716,8 @@ public Component getFailureTooltip() record PlayerHasReputation(int amount, boolean greaterThan) implements Condition { static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - PreservingOptionalFieldCodec.withDefault(Codec.INT, "amount", 1).forGetter(PlayerHasReputation::amount), - PreservingOptionalFieldCodec.withDefault(Codec.BOOL, "greater_than", true).forGetter(PlayerHasReputation::greaterThan) + ExtraCodecs.strictOptionalField(Codec.INT, "amount", 1).forGetter(PlayerHasReputation::amount), + ExtraCodecs.strictOptionalField(Codec.BOOL, "greater_than", true).forGetter(PlayerHasReputation::greaterThan) ).apply(instance, PlayerHasReputation::new)); @Override @@ -754,7 +753,7 @@ public Component getFailureTooltip() record PlayerHasBoondollars(int amount) implements Condition { static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - PreservingOptionalFieldCodec.withDefault(Codec.INT, "amount", 1).forGetter(PlayerHasBoondollars::amount) + ExtraCodecs.strictOptionalField(Codec.INT, "amount", 1).forGetter(PlayerHasBoondollars::amount) ).apply(instance, PlayerHasBoondollars::new)); @Override @@ -814,7 +813,7 @@ public Component getFailureTooltip() record CustomHasScore(int value, String ownerName, String objectiveName) implements Condition { static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - PreservingOptionalFieldCodec.withDefault(Codec.INT, "value", 0).forGetter(CustomHasScore::value), + ExtraCodecs.strictOptionalField(Codec.INT, "value", 0).forGetter(CustomHasScore::value), Codec.STRING.fieldOf("owner_name").forGetter(CustomHasScore::ownerName), Codec.STRING.fieldOf("objective_name").forGetter(CustomHasScore::objectiveName) ).apply(instance, CustomHasScore::new)); diff --git a/src/main/java/com/mraof/minestuck/entity/item/GristEntity.java b/src/main/java/com/mraof/minestuck/entity/item/GristEntity.java index a39bc4a2ef..93709b4da7 100644 --- a/src/main/java/com/mraof/minestuck/entity/item/GristEntity.java +++ b/src/main/java/com/mraof/minestuck/entity/item/GristEntity.java @@ -13,7 +13,6 @@ import com.mraof.minestuck.player.GristCache; import com.mraof.minestuck.player.IdentifierHandler; import com.mraof.minestuck.player.PlayerIdentifier; -import com.mraof.minestuck.util.MSNBTUtil; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; @@ -290,7 +289,7 @@ protected void addAdditionalSaveData(CompoundTag compound) compound.putShort("Health", (short) this.gristHealth); compound.putShort("Age", (short) this.gristAge); compound.putLong("Value", (short) this.gristValue); - MSNBTUtil.writeGristType(compound, "Type", gristType); + compound.put("Type", GristHelper.encodeGristType(gristType)); } @Override @@ -301,7 +300,7 @@ protected void readAdditionalSaveData(CompoundTag compound) if(compound.contains("Value", Tag.TAG_ANY_NUMERIC)) this.gristValue = compound.getLong("Value"); if(compound.contains("Type", Tag.TAG_STRING)) - this.gristType = MSNBTUtil.readGristType(compound, "Type"); + this.gristType = GristHelper.parseGristType(compound.get("Type")).orElseGet(GristTypes.BUILD); } /** @@ -378,4 +377,4 @@ public void readSpawnData(FriendlyByteBuf data) gristType = data.readById(GristTypes.REGISTRY); gristValue = data.readLong(); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/entity/underling/BasiliskEntity.java b/src/main/java/com/mraof/minestuck/entity/underling/BasiliskEntity.java index b5e3cb5091..47263484b3 100644 --- a/src/main/java/com/mraof/minestuck/entity/underling/BasiliskEntity.java +++ b/src/main/java/com/mraof/minestuck/entity/underling/BasiliskEntity.java @@ -9,7 +9,6 @@ import com.mraof.minestuck.entity.animation.MobAnimation; import com.mraof.minestuck.entity.animation.PhasedMobAnimation; import com.mraof.minestuck.player.EcheladderBonusType; -import com.mraof.minestuck.util.AnimationControllerUtil; import com.mraof.minestuck.util.MSSoundEvents; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.damagesource.DamageSource; @@ -22,10 +21,7 @@ import net.neoforged.neoforge.entity.PartEntity; import org.joml.Vector3d; import software.bernie.geckolib.animatable.GeoEntity; -import software.bernie.geckolib.core.animation.AnimatableManager; -import software.bernie.geckolib.core.animation.Animation; -import software.bernie.geckolib.core.animation.AnimationState; -import software.bernie.geckolib.core.animation.RawAnimation; +import software.bernie.geckolib.core.animation.*; import software.bernie.geckolib.core.object.PlayState; import javax.annotation.ParametersAreNonnullByDefault; @@ -226,10 +222,10 @@ public void contactPhaseStart(MobAnimation.Action animation) @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { - controllers.add(AnimationControllerUtil.createAnimation(this, "idleAnimation", 1, BasiliskEntity::idleAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "walkAnimation", 0.5, BasiliskEntity::walkAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "deathAnimation", 1, BasiliskEntity::deathAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "attackAnimation", 1, BasiliskEntity::attackAnimation)); + controllers.add(new AnimationController<>(this, "idleAnimation", BasiliskEntity::idleAnimation)); + controllers.add(new AnimationController<>(this, "walkAnimation", BasiliskEntity::walkAnimation).setAnimationSpeed(0.5)); + controllers.add(new AnimationController<>(this, "deathAnimation", BasiliskEntity::deathAnimation)); + controllers.add(new AnimationController<>(this, "attackAnimation", BasiliskEntity::attackAnimation)); } private static PlayState idleAnimation(AnimationState state) @@ -286,4 +282,4 @@ private static PlayState attackAnimation(AnimationState state) state.getController().forceAnimationReset(); return PlayState.STOP; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/entity/underling/GiclopsEntity.java b/src/main/java/com/mraof/minestuck/entity/underling/GiclopsEntity.java index 8e4fbdd94a..c889a36d1a 100644 --- a/src/main/java/com/mraof/minestuck/entity/underling/GiclopsEntity.java +++ b/src/main/java/com/mraof/minestuck/entity/underling/GiclopsEntity.java @@ -2,14 +2,13 @@ import com.mraof.minestuck.MinestuckConfig; import com.mraof.minestuck.alchemy.GristHelper; -import com.mraof.minestuck.api.alchemy.MutableGristSet; import com.mraof.minestuck.api.alchemy.GristType; +import com.mraof.minestuck.api.alchemy.MutableGristSet; import com.mraof.minestuck.entity.ai.attack.AnimatedAttackWhenInRangeGoal; import com.mraof.minestuck.entity.ai.attack.MoveToTargetGoal; import com.mraof.minestuck.entity.animation.MobAnimation; import com.mraof.minestuck.entity.animation.PhasedMobAnimation; import com.mraof.minestuck.player.EcheladderBonusType; -import com.mraof.minestuck.util.AnimationControllerUtil; import com.mraof.minestuck.util.MSSoundEvents; import net.minecraft.sounds.SoundEvent; import net.minecraft.tags.TagKey; @@ -23,10 +22,7 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.phys.AABB; import software.bernie.geckolib.animatable.GeoEntity; -import software.bernie.geckolib.core.animation.AnimatableManager; -import software.bernie.geckolib.core.animation.Animation; -import software.bernie.geckolib.core.animation.AnimationState; -import software.bernie.geckolib.core.animation.RawAnimation; +import software.bernie.geckolib.core.animation.*; import software.bernie.geckolib.core.object.PlayState; import javax.annotation.ParametersAreNonnullByDefault; @@ -172,10 +168,10 @@ public void initiationPhaseStart(MobAnimation.Action animation) @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { - controllers.add(AnimationControllerUtil.createAnimation(this, "idleAnimation", 1, GiclopsEntity::idleAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "walkAnimation", 1, GiclopsEntity::walkAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "attackAnimation", 1, GiclopsEntity::attackAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "deathAnimation", 1, GiclopsEntity::deathAnimation)); + controllers.add(new AnimationController<>(this, "idleAnimation", GiclopsEntity::idleAnimation)); + controllers.add(new AnimationController<>(this, "walkAnimation", GiclopsEntity::walkAnimation)); + controllers.add(new AnimationController<>(this, "attackAnimation", GiclopsEntity::attackAnimation)); + controllers.add(new AnimationController<>(this, "deathAnimation", GiclopsEntity::deathAnimation)); } private static PlayState idleAnimation(AnimationState state) @@ -222,4 +218,4 @@ private static PlayState deathAnimation(AnimationState state) } return PlayState.STOP; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/entity/underling/ImpEntity.java b/src/main/java/com/mraof/minestuck/entity/underling/ImpEntity.java index 896a4360ab..307b4985fc 100644 --- a/src/main/java/com/mraof/minestuck/entity/underling/ImpEntity.java +++ b/src/main/java/com/mraof/minestuck/entity/underling/ImpEntity.java @@ -9,7 +9,6 @@ import com.mraof.minestuck.entity.animation.PhasedMobAnimation; import com.mraof.minestuck.player.Echeladder; import com.mraof.minestuck.player.EcheladderBonusType; -import com.mraof.minestuck.util.AnimationControllerUtil; import com.mraof.minestuck.util.MSSoundEvents; import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; @@ -23,10 +22,7 @@ import net.minecraft.world.level.Level; import net.neoforged.neoforge.common.util.FakePlayer; import software.bernie.geckolib.animatable.GeoEntity; -import software.bernie.geckolib.core.animation.AnimatableManager; -import software.bernie.geckolib.core.animation.Animation; -import software.bernie.geckolib.core.animation.AnimationState; -import software.bernie.geckolib.core.animation.RawAnimation; +import software.bernie.geckolib.core.animation.*; import software.bernie.geckolib.core.object.PlayState; import javax.annotation.ParametersAreNonnullByDefault; @@ -132,11 +128,11 @@ public void initiationPhaseStart(MobAnimation.Action animation) @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { - controllers.add(AnimationControllerUtil.createAnimation(this, "idleAnimation", 1, ImpEntity::idleAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "walkArmsAnimation", 1, ImpEntity::walkArmsAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "walkAnimation", 0.5, ImpEntity::walkAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "deathAnimation", 0.7, ImpEntity::deathAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "attackAnimation", 2, ImpEntity::attackAnimation)); + controllers.add(new AnimationController<>(this, "idleAnimation", ImpEntity::idleAnimation)); + controllers.add(new AnimationController<>(this, "walkArmsAnimation", ImpEntity::walkArmsAnimation)); + controllers.add(new AnimationController<>(this, "walkAnimation", ImpEntity::walkAnimation).setAnimationSpeed(0.5)); + controllers.add(new AnimationController<>(this, "deathAnimation", ImpEntity::deathAnimation).setAnimationSpeed(0.7)); + controllers.add(new AnimationController<>(this, "attackAnimation", ImpEntity::attackAnimation).setAnimationSpeed(2)); } private static PlayState idleAnimation(AnimationState state) @@ -205,4 +201,5 @@ private static PlayState attackAnimation(AnimationState state) state.getController().forceAnimationReset(); return PlayState.STOP; } -} \ No newline at end of file +} + diff --git a/src/main/java/com/mraof/minestuck/entity/underling/LichEntity.java b/src/main/java/com/mraof/minestuck/entity/underling/LichEntity.java index 8a026116f1..4517da351e 100644 --- a/src/main/java/com/mraof/minestuck/entity/underling/LichEntity.java +++ b/src/main/java/com/mraof/minestuck/entity/underling/LichEntity.java @@ -8,7 +8,6 @@ import com.mraof.minestuck.entity.animation.MobAnimation; import com.mraof.minestuck.entity.animation.PhasedMobAnimation; import com.mraof.minestuck.player.EcheladderBonusType; -import com.mraof.minestuck.util.AnimationControllerUtil; import com.mraof.minestuck.util.MSSoundEvents; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.damagesource.DamageSource; @@ -21,10 +20,7 @@ import net.minecraft.world.entity.ai.goal.Goal; import net.minecraft.world.level.Level; import software.bernie.geckolib.animatable.GeoEntity; -import software.bernie.geckolib.core.animation.AnimatableManager; -import software.bernie.geckolib.core.animation.Animation; -import software.bernie.geckolib.core.animation.AnimationState; -import software.bernie.geckolib.core.animation.RawAnimation; +import software.bernie.geckolib.core.animation.*; import software.bernie.geckolib.core.object.PlayState; import javax.annotation.ParametersAreNonnullByDefault; @@ -133,10 +129,10 @@ public void initiationPhaseStart(MobAnimation.Action animation) @Override public void registerControllers(AnimatableManager.ControllerRegistrar controller) { - controller.add(AnimationControllerUtil.createAnimation(this, "idleAnimation", 1, LichEntity::idleAnimation)); - controller.add(AnimationControllerUtil.createAnimation(this, "walkAnimation", 1, LichEntity::walkAnimation)); - controller.add(AnimationControllerUtil.createAnimation(this, "deathAnimation", 1, LichEntity::deathAnimation)); - controller.add(AnimationControllerUtil.createAnimation(this, "attackAnimation", 2.25, LichEntity::attackAnimation)); + controller.add(new AnimationController<>(this, "idleAnimation", LichEntity::idleAnimation)); + controller.add(new AnimationController<>(this, "walkAnimation", LichEntity::walkAnimation)); + controller.add(new AnimationController<>(this, "deathAnimation", LichEntity::deathAnimation)); + controller.add(new AnimationController<>(this, "attackAnimation", LichEntity::attackAnimation).setAnimationSpeed(2.25)); } private static PlayState idleAnimation(AnimationState state) @@ -216,4 +212,4 @@ public void stop() instance.removeModifier(RESISTANCE_MODIFIER_ATTACKING.getId()); } } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/entity/underling/OgreEntity.java b/src/main/java/com/mraof/minestuck/entity/underling/OgreEntity.java index bd50cf9efd..2a72f0c7f6 100644 --- a/src/main/java/com/mraof/minestuck/entity/underling/OgreEntity.java +++ b/src/main/java/com/mraof/minestuck/entity/underling/OgreEntity.java @@ -1,15 +1,14 @@ package com.mraof.minestuck.entity.underling; import com.mraof.minestuck.alchemy.GristHelper; -import com.mraof.minestuck.api.alchemy.MutableGristSet; import com.mraof.minestuck.api.alchemy.GristType; +import com.mraof.minestuck.api.alchemy.MutableGristSet; import com.mraof.minestuck.entity.ai.attack.AnimatedAttackWhenInRangeGoal; import com.mraof.minestuck.entity.ai.attack.GroundSlamGoal; import com.mraof.minestuck.entity.ai.attack.MoveToTargetGoal; import com.mraof.minestuck.entity.animation.MobAnimation; import com.mraof.minestuck.entity.animation.PhasedMobAnimation; import com.mraof.minestuck.player.EcheladderBonusType; -import com.mraof.minestuck.util.AnimationControllerUtil; import com.mraof.minestuck.util.MSSoundEvents; import net.minecraft.sounds.SoundEvent; import net.minecraft.world.damagesource.DamageSource; @@ -19,10 +18,7 @@ import net.minecraft.world.entity.ai.attributes.AttributeSupplier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.level.Level; -import software.bernie.geckolib.core.animation.AnimatableManager; -import software.bernie.geckolib.core.animation.Animation; -import software.bernie.geckolib.core.animation.AnimationState; -import software.bernie.geckolib.core.animation.RawAnimation; +import software.bernie.geckolib.core.animation.*; import software.bernie.geckolib.core.object.PlayState; import javax.annotation.ParametersAreNonnullByDefault; @@ -126,10 +122,10 @@ public void initiationPhaseStart(MobAnimation.Action animation) @Override public void registerControllers(AnimatableManager.ControllerRegistrar controllers) { - controllers.add(AnimationControllerUtil.createAnimation(this, "walkArmsAnimation", 0.3, OgreEntity::walkArmsAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "walkAnimation", 0.3, OgreEntity::walkAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "attackAnimation", 0.5, OgreEntity::attackAnimation)); - controllers.add(AnimationControllerUtil.createAnimation(this, "deathAnimation", 0.85, OgreEntity::deathAnimation)); + controllers.add(new AnimationController<>(this, "walkArmsAnimation", OgreEntity::walkArmsAnimation).setAnimationSpeed(0.3)); + controllers.add(new AnimationController<>(this, "walkAnimation", OgreEntity::walkAnimation).setAnimationSpeed(0.3)); + controllers.add(new AnimationController<>(this, "attackAnimation", OgreEntity::attackAnimation).setAnimationSpeed(0.5)); + controllers.add(new AnimationController<>(this, "deathAnimation", OgreEntity::deathAnimation).setAnimationSpeed(0.85)); } private static PlayState walkAnimation(AnimationState state) @@ -183,4 +179,4 @@ private static PlayState deathAnimation(AnimationState state) } return PlayState.STOP; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/entity/underling/UnderlingEntity.java b/src/main/java/com/mraof/minestuck/entity/underling/UnderlingEntity.java index d3e6ad097e..c79ff0158e 100644 --- a/src/main/java/com/mraof/minestuck/entity/underling/UnderlingEntity.java +++ b/src/main/java/com/mraof/minestuck/entity/underling/UnderlingEntity.java @@ -15,7 +15,6 @@ import com.mraof.minestuck.player.EcheladderBonusType; import com.mraof.minestuck.player.IdentifierHandler; import com.mraof.minestuck.player.PlayerIdentifier; -import com.mraof.minestuck.util.MSNBTUtil; import com.mraof.minestuck.util.MSTags; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; @@ -282,7 +281,8 @@ public void addEnemy(EntityType enemyType) public void addAdditionalSaveData(CompoundTag compound) { super.addAdditionalSaveData(compound); - MSNBTUtil.writeGristType(compound, "Type", getGristType()); + GristType gristType = getGristType(); + compound.put("Type", GristHelper.encodeGristType(gristType)); compound.putBoolean("Spawned", fromSpawner); if(hasRestriction()) { @@ -301,7 +301,7 @@ public void readAdditionalSaveData(CompoundTag compound) { //Note: grist type should be read and applied before reading health due to the modifiers to max health if(compound.contains("Type", Tag.TAG_STRING)) - applyGristType(MSNBTUtil.readGristType(compound, "Type", GristTypes.ARTIFACT)); + applyGristType(GristHelper.parseGristType(compound.get("Type")).orElseGet(GristTypes.ARTIFACT)); else applyGristType(GristHelper.getPrimaryGrist(this.getRandom())); super.readAdditionalSaveData(compound); diff --git a/src/main/java/com/mraof/minestuck/entry/EntryProcess.java b/src/main/java/com/mraof/minestuck/entry/EntryProcess.java index 46d8c7fa92..eba5cf7d44 100644 --- a/src/main/java/com/mraof/minestuck/entry/EntryProcess.java +++ b/src/main/java/com/mraof/minestuck/entry/EntryProcess.java @@ -317,7 +317,7 @@ private void finalizeEntry(ServerPlayer player, ServerLevel level0, ServerLevel placeGates(level1); - MSExtraData.get(level1).addPostEntryTask(new PostEntryTask(level1.dimension(), origin.getX() + xDiff, origin.getY() + yDiff, origin.getZ() + zDiff, artifactRange, (byte) 0)); + MSExtraData.get(level1).addPostEntryTask(new PostEntryTask(level1.dimension(), origin.getX() + xDiff, origin.getY() + yDiff, origin.getZ() + zDiff, artifactRange)); } private static void removeDroppedEntities(ServerPlayer player, ServerLevel level0, AABB entityTeleportBB, List entities) @@ -478,4 +478,4 @@ public static void placeGates(ServerLevel level) GateBlock.placeGate(level, new BlockPos(0, GateHandler.GATE_HEIGHT_1, 0), GateHandler.Type.GATE_1, 0); GateBlock.placeGate(level, new BlockPos(0, GateHandler.GATE_HEIGHT_2, 0), GateHandler.Type.GATE_2, 0); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/entry/PostEntryTask.java b/src/main/java/com/mraof/minestuck/entry/PostEntryTask.java index 5de5cceb1e..c904a3eed7 100644 --- a/src/main/java/com/mraof/minestuck/entry/PostEntryTask.java +++ b/src/main/java/com/mraof/minestuck/entry/PostEntryTask.java @@ -1,8 +1,8 @@ package com.mraof.minestuck.entry; -import com.mraof.minestuck.util.MSNBTUtil; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -16,9 +16,23 @@ * To reduce time, and still reduce lightning and "floating" liquids, * this was created to handle such tasks during the ticks right after entry instead of during entry. */ -public class PostEntryTask +public final class PostEntryTask { private static final Logger LOGGER = LogManager.getLogger(); + + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Level.RESOURCE_KEY_CODEC.fieldOf("dimension").forGetter(task -> task.dimension), + Codec.INT.fieldOf("x").forGetter(task -> task.x), + Codec.INT.fieldOf("y").forGetter(task -> task.y), + Codec.INT.fieldOf("z").forGetter(task -> task.z), + Codec.INT.fieldOf("entrySize").forGetter(task -> task.entrySize), + Codec.INT.fieldOf("index").forGetter(task -> task.index) + ).apply(instance, (dimension, x, y, z, entrySize, index) -> { + PostEntryTask task = new PostEntryTask(dimension, x, y, z, entrySize); + task.index = index; + return task; + })); + /** * The minimum amount of time (in milliseconds) to spend each game tick * updating blocks post-entry. @@ -29,42 +43,18 @@ public class PostEntryTask private final ResourceKey dimension; private final int x, y, z; private final int entrySize; - private final byte entryType; //Used if we add more ways for entry to happen private int index; - public PostEntryTask(ResourceKey dimension, int xCoord, int yCoord, int zCoord, int entrySize, byte entryType) + public PostEntryTask(ResourceKey dimension, int xCoord, int yCoord, int zCoord, int entrySize) { this.dimension = dimension; this.x = xCoord; this.y = yCoord; this.z = zCoord; this.entrySize = entrySize; - this.entryType = entryType; this.index = 0; } - public PostEntryTask(CompoundTag nbt) - { - this(MSNBTUtil.tryReadDimensionType(nbt, "dimension"), nbt.getInt("x"), nbt.getInt("y"), nbt.getInt("z"), nbt.getInt("entrySize"), nbt.getByte("entryType")); - this.index = nbt.getInt("index"); - if(dimension == null) - LOGGER.warn("Unable to load dimension type by name {}!", nbt.getString("dimension")); - } - - public CompoundTag write() - { - CompoundTag nbt = new CompoundTag(); - MSNBTUtil.tryWriteDimensionType(nbt, "dimension", dimension); - nbt.putInt("x", x); - nbt.putInt("y", y); - nbt.putInt("z", z); - nbt.putInt("entrySize", entrySize); - nbt.putByte("entryType", entryType); - nbt.putInt("index", index); - - return nbt; - } - public boolean onTick(MinecraftServer server) { if(isDone()) @@ -80,32 +70,27 @@ public boolean onTick(MinecraftServer server) } int preIndex = index; - main: + + long time = System.currentTimeMillis() + MIN_TIME; + int i = 0; + for(BlockPos pos : EntryBlockIterator.get(x, y, z, entrySize)) { - if(entryType == 0) + if(i >= index) { - long time = System.currentTimeMillis() + MIN_TIME; - int i = 0; - for(BlockPos pos : EntryBlockIterator.get(x, y, z, entrySize)) + updateBlock(pos.immutable(), world); + index++; + if(time <= System.currentTimeMillis()) { - if(i >= index) - { - updateBlock(pos.immutable(), world); - index++; - if(time <= System.currentTimeMillis()) - break main; - } - i++; + LOGGER.debug("Updated {} blocks this tick.", index - preIndex); + return index != preIndex; } } - - LOGGER.info("Completed entry block updates for dimension {}.", dimension.location()); - setDone(); - return true; + i++; } - LOGGER.debug("Updated {} blocks this tick.", index - preIndex); - return index != preIndex; + LOGGER.info("Completed entry block updates for dimension {}.", dimension.location()); + setDone(); + return true; } public boolean isDone() @@ -125,4 +110,4 @@ private static void updateBlock(BlockPos pos, ServerLevel level) level.sendBlockUpdated(pos, blockState, blockState, 0); level.updateNeighborsAt(pos, blockState.getBlock()); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/item/IncompleteSburbCodeItem.java b/src/main/java/com/mraof/minestuck/item/IncompleteSburbCodeItem.java index 3c6018bcf7..6e391e8f6b 100644 --- a/src/main/java/com/mraof/minestuck/item/IncompleteSburbCodeItem.java +++ b/src/main/java/com/mraof/minestuck/item/IncompleteSburbCodeItem.java @@ -1,11 +1,12 @@ package com.mraof.minestuck.item; import com.mraof.minestuck.blockentity.ComputerBlockEntity; -import com.mraof.minestuck.util.MSNBTUtil; import com.mraof.minestuck.util.MSTags; import net.minecraft.client.gui.screens.Screen; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.StringTag; import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; @@ -22,6 +23,7 @@ import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; +import javax.annotation.Nonnull; import java.util.Collections; import java.util.List; import java.util.Set; @@ -87,12 +89,12 @@ public Set getRecordedBlocks(ItemStack stack) */ public static boolean addRecordedInfo(ItemStack stack, Block block) { - return MSNBTUtil.tryAddBlockToSet(stack.getOrCreateTag(), "recordedHieroglyphs", block); + return tryAddBlockToSet(stack.getOrCreateTag(), "recordedHieroglyphs", block); } public static ItemStack setRecordedInfo(ItemStack stack, Set blockList) { - MSNBTUtil.writeBlockSet(stack.getOrCreateTag(), "recordedHieroglyphs", blockList); + writeBlockSet(stack.getOrCreateTag(), "recordedHieroglyphs", blockList); return stack; } @@ -187,4 +189,47 @@ public void appendHoverText(ItemStack stack, @Nullable Level level, List readBlockSet(CompoundTag nbt, String key) + { + return nbt.getList(key, Tag.TAG_STRING).stream().map(Tag::getAsString) + //Turn the Strings into ResourceLocations + .flatMap(blockName -> Stream.ofNullable(ResourceLocation.tryParse(blockName))) + //Turn the ResourceLocations into Blocks + .flatMap(blockId -> Stream.ofNullable(BuiltInRegistries.BLOCK.get(blockId))) + //Gather the blocks into a set + .collect(Collectors.toSet()); + } + + public static void writeBlockSet(CompoundTag nbt, String key, @Nonnull Set blocks) + { + ListTag listTag = new ListTag(); + for(Block blockIterate : blocks) + { + String blockName = String.valueOf(BuiltInRegistries.BLOCK.getKey(blockIterate)); + listTag.add(StringTag.valueOf(blockName)); + } + + nbt.put(key, listTag); + } + + public static boolean tryAddBlockToSet(CompoundTag nbt, String key, Block block) + { + StringTag blockIdTag = StringTag.valueOf(String.valueOf(BuiltInRegistries.BLOCK.getKey(block))); + + if(!nbt.contains(key, Tag.TAG_LIST)) + { + writeBlockSet(nbt, key, Collections.singleton(block)); + return true; + } else + { + ListTag listTag = nbt.getList(key, Tag.TAG_STRING); + if(!listTag.contains(blockIdTag)) + { + listTag.add(blockIdTag); + return true; + } else + return false; + } + } } diff --git a/src/main/java/com/mraof/minestuck/util/DispenserBehaviourUtil.java b/src/main/java/com/mraof/minestuck/item/MSDispenserBehaviours.java similarity index 93% rename from src/main/java/com/mraof/minestuck/util/DispenserBehaviourUtil.java rename to src/main/java/com/mraof/minestuck/item/MSDispenserBehaviours.java index f1a0fc3c59..3cf1cb7a41 100644 --- a/src/main/java/com/mraof/minestuck/util/DispenserBehaviourUtil.java +++ b/src/main/java/com/mraof/minestuck/item/MSDispenserBehaviours.java @@ -1,6 +1,5 @@ -package com.mraof.minestuck.util; +package com.mraof.minestuck.item; -import com.mraof.minestuck.item.MSItems; import net.minecraft.core.BlockPos; import net.minecraft.core.dispenser.BlockSource; import net.minecraft.core.dispenser.DefaultDispenseItemBehavior; @@ -10,7 +9,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.block.DispenserBlock; -public class DispenserBehaviourUtil +public final class MSDispenserBehaviours { // Add dispenser behaviour for items with classes we do not own public static void registerBehaviours() { diff --git a/src/main/java/com/mraof/minestuck/skaianet/DataCheckerManager.java b/src/main/java/com/mraof/minestuck/skaianet/DataCheckerManager.java index eab12dbe41..22fa071939 100644 --- a/src/main/java/com/mraof/minestuck/skaianet/DataCheckerManager.java +++ b/src/main/java/com/mraof/minestuck/skaianet/DataCheckerManager.java @@ -3,7 +3,6 @@ import com.mraof.minestuck.network.DataCheckerPacket; import com.mraof.minestuck.player.PlayerIdentifier; import com.mraof.minestuck.player.Title; -import com.mraof.minestuck.util.DataCheckerPermission; import com.mraof.minestuck.world.lands.LandTypePair; import com.mraof.minestuck.world.lands.LandTypes; import com.mraof.minestuck.world.lands.terrain.TerrainLandType; diff --git a/src/main/java/com/mraof/minestuck/util/DataCheckerPermission.java b/src/main/java/com/mraof/minestuck/skaianet/DataCheckerPermission.java similarity index 79% rename from src/main/java/com/mraof/minestuck/util/DataCheckerPermission.java rename to src/main/java/com/mraof/minestuck/skaianet/DataCheckerPermission.java index e0b5a1e9bc..1fd11088f5 100644 --- a/src/main/java/com/mraof/minestuck/util/DataCheckerPermission.java +++ b/src/main/java/com/mraof/minestuck/skaianet/DataCheckerPermission.java @@ -1,4 +1,4 @@ -package com.mraof.minestuck.util; +package com.mraof.minestuck.skaianet; import com.mraof.minestuck.Minestuck; import com.mraof.minestuck.MinestuckConfig; @@ -22,24 +22,24 @@ import java.util.UUID; @Mod.EventBusSubscriber(modid = Minestuck.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE) -public class DataCheckerPermission +public final class DataCheckerPermission { - private static Set dataCheckerPermission = new HashSet<>(); + private static final Set dataCheckerPermission = new HashSet<>(); @SubscribeEvent - public static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) + private static void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) { sendPacket((ServerPlayer) event.getEntity()); } @SubscribeEvent - public static void onPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) + private static void onPlayerLogout(PlayerEvent.PlayerLoggedOutEvent event) { dataCheckerPermission.remove(event.getEntity().getGameProfile().getId()); } @SubscribeEvent - public static void onPlayerTick(TickEvent.PlayerTickEvent event) + private static void onPlayerTick(TickEvent.PlayerTickEvent event) { if(event.side == LogicalSide.SERVER && event.phase == TickEvent.Phase.END && event.player instanceof ServerPlayer player) { @@ -49,7 +49,7 @@ public static void onPlayerTick(TickEvent.PlayerTickEvent event) } @SubscribeEvent - public static void serverStopped(ServerStoppedEvent event) + private static void serverStopped(ServerStoppedEvent event) { dataCheckerPermission.clear(); } @@ -73,14 +73,14 @@ private static void sendPacket(ServerPlayer player) public static boolean hasPermission(ServerPlayer player) { - switch(MinestuckConfig.SERVER.dataCheckerPermission.get()) + return switch(MinestuckConfig.SERVER.dataCheckerPermission.get()) { - case ANYONE: return true; - case OPS: return hasOp(player); - case GAMEMODE: return hasGamemodePermission(player); - case OPS_OR_GAMEMODE: return hasOp(player) || hasGamemodePermission(player); - case NONE: default: return false; - } + case ANYONE -> true; + case OPS -> hasOp(player); + case GAMEMODE -> hasGamemodePermission(player); + case OPS_OR_GAMEMODE -> hasOp(player) || hasGamemodePermission(player); + case NONE -> false; + }; } private static boolean hasGamemodePermission(ServerPlayer player) @@ -104,4 +104,4 @@ private static boolean hasOp(ServerPlayer player) } return false; } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/skaianet/SburbPlayerData.java b/src/main/java/com/mraof/minestuck/skaianet/SburbPlayerData.java index bd0b3a04b4..5e475a5a0b 100644 --- a/src/main/java/com/mraof/minestuck/skaianet/SburbPlayerData.java +++ b/src/main/java/com/mraof/minestuck/skaianet/SburbPlayerData.java @@ -1,5 +1,6 @@ package com.mraof.minestuck.skaianet; +import com.mraof.minestuck.alchemy.GristHelper; import com.mraof.minestuck.api.alchemy.GristType; import com.mraof.minestuck.computer.editmode.DeployEntry; import com.mraof.minestuck.computer.editmode.EditData; @@ -8,7 +9,6 @@ import com.mraof.minestuck.network.computer.SkaianetInfoPacket; import com.mraof.minestuck.player.IdentifierHandler; import com.mraof.minestuck.player.PlayerIdentifier; -import com.mraof.minestuck.util.MSNBTUtil; import net.minecraft.nbt.*; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; @@ -73,7 +73,8 @@ void read(CompoundTag tag) } this.artifactType = ArtifactType.fromInt(tag.getInt("artifact")); - this.baseGrist = MSNBTUtil.readGristType(tag, "base_grist", () -> SburbHandler.generateGristType(new Random())); + this.baseGrist = GristHelper.parseGristType(tag.get("base_grist")) + .orElseGet(() -> SburbHandler.generateGristType(new Random())); } void write(CompoundTag tag) @@ -94,7 +95,7 @@ void write(CompoundTag tag) } tag.putInt("artifact", this.artifactType.ordinal()); - MSNBTUtil.writeGristType(tag, "base_grist", this.baseGrist); + tag.put("base_grist", GristHelper.encodeGristType(this.baseGrist)); } void readOldData(CompoundTag tag) @@ -116,7 +117,8 @@ void readOldData(CompoundTag tag) } artifactType = ArtifactType.fromInt(tag.getInt("artifact")); - baseGrist = MSNBTUtil.readGristType(tag, "base_grist", () -> SburbHandler.generateGristType(new Random())); + baseGrist = GristHelper.parseGristType(tag.get("base_grist")) + .orElseGet(() -> SburbHandler.generateGristType(new Random())); } public PlayerIdentifier playerId() diff --git a/src/main/java/com/mraof/minestuck/util/AnimationControllerUtil.java b/src/main/java/com/mraof/minestuck/util/AnimationControllerUtil.java deleted file mode 100644 index 4efe48a01f..0000000000 --- a/src/main/java/com/mraof/minestuck/util/AnimationControllerUtil.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.mraof.minestuck.util; - -import software.bernie.geckolib.core.animatable.GeoAnimatable; -import software.bernie.geckolib.core.animation.AnimationController; - -/** - * Collection of helper functions for common-side animations. - */ -public final class AnimationControllerUtil -{ - /** - * Helper to create a new animation controller with custom animation speed - * - * @param name name of this controller - * @param speed animation speed - default speed is 1 - * @param predicate the animation predicate - * @return a configured animation controller with speed - */ - public static AnimationController createAnimation(T entity, String name, double speed, AnimationController.AnimationStateHandler predicate) - { - AnimationController controller = new AnimationController<>(entity, name, 0, predicate); - controller.setAnimationSpeed(speed); - return controller; - } -} diff --git a/src/main/java/com/mraof/minestuck/util/BoondollarPriceManager.java b/src/main/java/com/mraof/minestuck/util/BoondollarPriceManager.java deleted file mode 100644 index 54f317d606..0000000000 --- a/src/main/java/com/mraof/minestuck/util/BoondollarPriceManager.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.mraof.minestuck.util; - -import com.google.common.collect.ImmutableList; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonElement; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.packs.resources.ResourceManager; -import net.minecraft.server.packs.resources.SimpleJsonResourceReloadListener; -import net.minecraft.util.RandomSource; -import net.minecraft.util.profiling.ProfilerFiller; -import net.minecraft.world.item.ItemStack; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.Mod; -import net.neoforged.neoforge.event.AddReloadListenerEvent; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - - -@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE) -public class BoondollarPriceManager extends SimpleJsonResourceReloadListener -{ - private static final Logger LOGGER = LogManager.getLogger(); - private static final Gson GSON = new GsonBuilder().registerTypeAdapter(BoondollarPricing.class, new BoondollarPricing.Serializer()).create(); - - private List pricings; - - public BoondollarPriceManager() - { - super(GSON, "minestuck/boondollar_prices"); - } - - private static BoondollarPriceManager INSTANCE; - - public static BoondollarPriceManager getInstance() - { - return Objects.requireNonNull(INSTANCE); - } - - @Override - protected void apply(Map jsonEntries, ResourceManager resourceManager, ProfilerFiller profiler) - { - ImmutableList.Builder pricings = ImmutableList.builder(); - for(Map.Entry entry : jsonEntries.entrySet()) - { - try - { - BoondollarPricing pricing = GSON.fromJson(entry.getValue(), BoondollarPricing.class); - pricings.add(pricing); - } catch(Exception e) - { - LOGGER.error("Couldn't parse boondollar pricing {}", entry.getKey(), e); - } - } - - this.pricings = pricings.build(); - LOGGER.info("Loaded {} boondollar prices", this.pricings.size()); - } - - public Optional findPrice(ItemStack stack, RandomSource rand) - { - return pricings.stream().filter(pricing -> pricing.appliesTo(stack)).findAny().map(pricing -> pricing.generatePrice(rand)); - } - - public static JsonElement parsePrice(BoondollarPricing pricing) - { - return GSON.toJsonTree(pricing); - } - - @SubscribeEvent - public static void onResourceReload(AddReloadListenerEvent event) - { - event.addListener(INSTANCE = new BoondollarPriceManager()); - } -} \ No newline at end of file diff --git a/src/main/java/com/mraof/minestuck/util/BoondollarPricing.java b/src/main/java/com/mraof/minestuck/util/BoondollarPricing.java deleted file mode 100644 index b7472cef9b..0000000000 --- a/src/main/java/com/mraof/minestuck/util/BoondollarPricing.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.mraof.minestuck.util; - -import com.google.gson.*; -import com.mojang.logging.LogUtils; -import com.mojang.serialization.JsonOps; -import net.minecraft.util.GsonHelper; -import net.minecraft.util.RandomSource; -import net.minecraft.util.valueproviders.IntProvider; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.crafting.Ingredient; -import org.slf4j.Logger; - -import java.lang.reflect.Type; - -public class BoondollarPricing -{ - private static final Logger LOGGER = LogUtils.getLogger(); - - private final Ingredient ingredient; - private final IntProvider priceRange; - - public BoondollarPricing(Ingredient ingredient, IntProvider priceRange) - { - this.ingredient = ingredient; - this.priceRange = priceRange; - } - - public int generatePrice(RandomSource random) - { - return priceRange.sample(random); - } - - public boolean appliesTo(ItemStack stack) - { - return ingredient.test(stack); - } - - //todo replace serializer with codec - public static class Serializer implements JsonDeserializer, JsonSerializer - { - @Override - public BoondollarPricing deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext context) throws JsonParseException - { - JsonObject json = GsonHelper.convertToJsonObject(jsonElement, "boolean pricing"); - IntProvider priceProvider = IntProvider.CODEC.parse(JsonOps.INSTANCE, json.get("range")).getOrThrow(false, LOGGER::error); - return new BoondollarPricing(Ingredient.fromJson(json.get("ingredient"), false), priceProvider); - } - - @Override - public JsonElement serialize(BoondollarPricing pricing, Type type, JsonSerializationContext context) - { - JsonObject json = new JsonObject(); - json.add("ingredient", Ingredient.CODEC_NONEMPTY.encodeStart(JsonOps.INSTANCE, pricing.ingredient).getOrThrow(false, LOGGER::error)); - json.add("range", IntProvider.CODEC.encodeStart(JsonOps.INSTANCE, pricing.priceRange).getOrThrow(false, LOGGER::error)); - return json; - } - } -} \ No newline at end of file diff --git a/src/main/java/com/mraof/minestuck/util/CoordPair.java b/src/main/java/com/mraof/minestuck/util/CoordPair.java index 8348037035..cbaa4f1300 100644 --- a/src/main/java/com/mraof/minestuck/util/CoordPair.java +++ b/src/main/java/com/mraof/minestuck/util/CoordPair.java @@ -1,28 +1,15 @@ package com.mraof.minestuck.util; +import net.minecraft.core.BlockPos; + /** * A simple x/z coordinate pair */ -public class CoordPair +public record CoordPair(int x, int z) { - public final int x; - public final int z; - public CoordPair(int x, int z) - { - this.x = x; - this.z = z; - } - - @Override - public boolean equals(Object obj) - { - return obj instanceof CoordPair && ((CoordPair) obj).x == x && ((CoordPair) obj).z == z; - } - - @Override - public int hashCode() + public BlockPos atY(int y) { - return (Integer.hashCode(x) << 16) | (Integer.hashCode(z) >> 16); + return new BlockPos(this.x, y, this.z); } public CoordPair north() @@ -44,4 +31,4 @@ public CoordPair east() { return new CoordPair(x + 1, z); } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/util/ExtraForgeTags.java b/src/main/java/com/mraof/minestuck/util/ExtraForgeTags.java index 3c819a4941..2e4981c104 100644 --- a/src/main/java/com/mraof/minestuck/util/ExtraForgeTags.java +++ b/src/main/java/com/mraof/minestuck/util/ExtraForgeTags.java @@ -10,13 +10,12 @@ /** * A place to put tags that forge doesn't add themselves, but which are generally expected to be filled by other mods. */ -public class ExtraForgeTags +public final class ExtraForgeTags { - public static class Blocks + public static final class Blocks { public static final TagKey URANIUM_ORES = tag("ores/uranium"); public static final TagKey URANIUM_STORAGE_BLOCKS = tag("storage_blocks/uranium"); - public static final TagKey TERRACOTTA = tag("terracotta"); private static TagKey tag(String name) { @@ -24,7 +23,7 @@ private static TagKey tag(String name) } } - public static class Items + public static final class Items { public static final TagKey URANIUM_ORES = tag("ores/uranium"); public static final TagKey TIN_ORES = tag("ores/tin"); @@ -51,7 +50,6 @@ public static class Items public static final TagKey URANIUM_STORAGE_BLOCKS = tag("storage_blocks/uranium"); public static final TagKey URANIUM_CHUNKS = tag("chunks/uranium"); - public static final TagKey TERRACOTTA = tag("terracotta"); public static final TagKey URANIUM_INGOTS = tag("ingots/uranium"); public static final TagKey TIN_INGOTS = tag("ingots/tin"); diff --git a/src/main/java/com/mraof/minestuck/util/LazyInstance.java b/src/main/java/com/mraof/minestuck/util/LazyInstance.java deleted file mode 100644 index bd68b8e3cf..0000000000 --- a/src/main/java/com/mraof/minestuck/util/LazyInstance.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.mraof.minestuck.util; - -import java.util.function.Supplier; - -public class LazyInstance -{ - private final Supplier supplier; - private T item = null; - - public LazyInstance(Supplier supplier) - { - this.supplier = supplier; - } - - public T get() - { - if(item == null) - item = supplier.get(); - return item; - } - - public void invalidate() - { - item = null; - } -} \ No newline at end of file diff --git a/src/main/java/com/mraof/minestuck/util/MSNBTUtil.java b/src/main/java/com/mraof/minestuck/util/MSNBTUtil.java deleted file mode 100644 index 99f4e9b07a..0000000000 --- a/src/main/java/com/mraof/minestuck/util/MSNBTUtil.java +++ /dev/null @@ -1,164 +0,0 @@ -package com.mraof.minestuck.util; - -import com.mraof.minestuck.api.alchemy.GristType; -import com.mraof.minestuck.api.alchemy.GristTypes; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.*; -import net.minecraft.resources.ResourceKey; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import java.util.Collections; -import java.util.Objects; -import java.util.Optional; -import java.util.Set; -import java.util.function.Supplier; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * Helper class for reading and writing objects (not provided by minestuck) from and to NBT. - * @author kirderf1 - */ -@SuppressWarnings("unused") -public class MSNBTUtil -{ - private static final Logger LOGGER = LogManager.getLogger(); - - /** - * Reads a resource location or throws an exception if it is invalid. - */ - @Nonnull - public static ResourceLocation readResourceLocation(CompoundTag nbt, String key) - { - return ResourceLocation.CODEC.parse(NbtOps.INSTANCE, nbt.get(key)).getOrThrow(false, LOGGER::error); - } - - /** - * Reads a resource location or returns null if it is invalid. - */ - @Nullable - public static ResourceLocation tryReadResourceLocation(CompoundTag nbt, String key) - { - return ResourceLocation.CODEC.parse(NbtOps.INSTANCE, nbt.get(key)).resultOrPartial(LOGGER::error).orElse(null); - } - - public static CompoundTag writeResourceLocation(CompoundTag nbt, String key, ResourceLocation resourceLocation) - { - Objects.requireNonNull(resourceLocation); - nbt.put(key, ResourceLocation.CODEC.encodeStart(NbtOps.INSTANCE, resourceLocation).getOrThrow(false, LOGGER::error)); - return nbt; - } - - /** - * Reads a dimension type or throws an exception if it is unable to do so. - */ - @Nonnull - public static ResourceKey readDimensionType(CompoundTag nbt, String key) - { - return Level.RESOURCE_KEY_CODEC.parse(NbtOps.INSTANCE, nbt.get(key)).getOrThrow(false, LOGGER::error); - } - - /** - * Reads a dimension type or returns null if it is unable to do so. - */ - @Nullable - public static ResourceKey tryReadDimensionType(CompoundTag nbt, String key) - { - return Level.RESOURCE_KEY_CODEC.parse(NbtOps.INSTANCE, nbt.get(key)).resultOrPartial(LOGGER::error).orElse(null); - } - - /** - * Writes a dimension type or throws an exception if it is unable to do so. - */ - public static CompoundTag writeDimensionType(CompoundTag nbt, String key, ResourceKey dimension) - { - nbt.put(key, Level.RESOURCE_KEY_CODEC.encodeStart(NbtOps.INSTANCE, dimension).getOrThrow(false, LOGGER::error)); - return nbt; - } - - /** - * Tries to write a dimension type and returns true if it is able to do so. - */ - public static boolean tryWriteDimensionType(CompoundTag nbt, String key, ResourceKey dimension) - { - Optional optional = Level.RESOURCE_KEY_CODEC.encodeStart(NbtOps.INSTANCE, dimension).resultOrPartial(LOGGER::error); - optional.ifPresent(inbt -> nbt.put(key, inbt)); - return optional.isPresent(); - } - - public static Set readBlockSet(CompoundTag nbt, String key) - { - return nbt.getList(key, Tag.TAG_STRING).stream().map(Tag::getAsString) - //Turn the Strings into ResourceLocations - .flatMap(blockName -> Stream.ofNullable(ResourceLocation.tryParse(blockName))) - //Turn the ResourceLocations into Blocks - .flatMap(blockId -> Stream.ofNullable(BuiltInRegistries.BLOCK.get(blockId))) - //Gather the blocks into a set - .collect(Collectors.toSet()); - } - - public static void writeBlockSet(CompoundTag nbt, String key, @Nonnull Set blocks) - { - ListTag listTag = new ListTag(); - for(Block blockIterate : blocks) - { - String blockName = String.valueOf(BuiltInRegistries.BLOCK.getKey(blockIterate)); - listTag.add(StringTag.valueOf(blockName)); - } - - nbt.put(key, listTag); - } - - public static boolean tryAddBlockToSet(CompoundTag nbt, String key, Block block) - { - StringTag blockIdTag = StringTag.valueOf(String.valueOf(BuiltInRegistries.BLOCK.getKey(block))); - - if(!nbt.contains(key, Tag.TAG_LIST)) - { - writeBlockSet(nbt, key, Collections.singleton(block)); - return true; - } else - { - ListTag listTag = nbt.getList(key, Tag.TAG_STRING); - if(!listTag.contains(blockIdTag)) - { - listTag.add(blockIdTag); - return true; - } else - return false; - } - } - - public static void writeGristType(CompoundTag nbt, String key, GristType gristType) - { - ResourceLocation id = gristType.getId(); - if(id == null) - LOGGER.error("Trying to save grist type {} that is lacking a registry id!", gristType); - else writeResourceLocation(nbt, key, id); - } - - public static GristType readGristType(CompoundTag nbt, String key) - { - return readGristType(nbt, key, GristTypes.BUILD); - } - - public static GristType readGristType(CompoundTag nbt, String key, Supplier fallback) - { - ResourceLocation name = tryReadResourceLocation(nbt, key); - if(name != null) - { - GristType type = GristTypes.REGISTRY.get(name); - if(type != null) - return type; - else - LOGGER.warn("Couldn't find grist type by name {} while reading from nbt. Will fall back to {} instead.", name, fallback); - } - return fallback.get(); - } -} \ No newline at end of file diff --git a/src/main/java/com/mraof/minestuck/util/MSSoundEvents.java b/src/main/java/com/mraof/minestuck/util/MSSoundEvents.java index 7c0d811dc5..6720003815 100644 --- a/src/main/java/com/mraof/minestuck/util/MSSoundEvents.java +++ b/src/main/java/com/mraof/minestuck/util/MSSoundEvents.java @@ -7,7 +7,7 @@ import java.util.function.Supplier; -public class MSSoundEvents +public final class MSSoundEvents { public static final DeferredRegister REGISTER = DeferredRegister.create(BuiltInRegistries.SOUND_EVENT, Minestuck.MOD_ID); @@ -114,6 +114,6 @@ public class MSSoundEvents private static Supplier register(String name) { - return REGISTER.register(name.replace(".","_"), () -> SoundEvent.createVariableRangeEvent(Minestuck.id(name))); + return REGISTER.register(name, () -> SoundEvent.createVariableRangeEvent(Minestuck.id(name))); } } diff --git a/src/main/java/com/mraof/minestuck/util/PositionTeleporter.java b/src/main/java/com/mraof/minestuck/util/PositionTeleporter.java deleted file mode 100644 index f7be04e469..0000000000 --- a/src/main/java/com/mraof/minestuck/util/PositionTeleporter.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.mraof.minestuck.util; - -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.world.entity.Entity; - -public class PositionTeleporter -{ - public double posX, posY, posZ; - - public static void moveEntity(Entity entity, double posX, double posY, double posZ) - { - entity.stopRiding(); - if(entity instanceof ServerPlayer player) - { - if (player.isSleeping()) - { - player.stopSleeping(); - } - - player.connection.teleport(posX, posY, posZ, entity.getYRot(), entity.getXRot()); - } else - { - entity.setPos(posX, posY, posZ); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/mraof/minestuck/util/PreservingOptionalFieldCodec.java b/src/main/java/com/mraof/minestuck/util/PreservingOptionalFieldCodec.java deleted file mode 100644 index 8859351d8c..0000000000 --- a/src/main/java/com/mraof/minestuck/util/PreservingOptionalFieldCodec.java +++ /dev/null @@ -1,84 +0,0 @@ -package com.mraof.minestuck.util; - -import com.mojang.serialization.*; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Stream; - -/** - * A version of {@link com.mojang.serialization.codecs.OptionalFieldCodec} that preserves any partial result or error from the wrapped codec. - * Note: In mc1.20.2+, this codec can be replaced by {@code ExtraCodecs.strictOptionalField()}. - */ -public final class PreservingOptionalFieldCodec extends MapCodec> -{ - public static MapCodec> forList(Codec> elementCodec, String name) - { - return new PreservingOptionalFieldCodec<>(elementCodec, name) - .xmap(optional -> optional.orElse(Collections.emptyList()), - list -> list.isEmpty() ? Optional.empty() : Optional.of(list)); - } - - public static MapCodec withDefault(Codec elementCodec, String name, A defaultValue) - { - return new PreservingOptionalFieldCodec<>(elementCodec, name) - .xmap(optional -> optional.orElse(defaultValue), - value -> value.equals(defaultValue) ? Optional.empty() : Optional.of(value)); - } - - private final Codec elementCodec; - private final String name; - - public PreservingOptionalFieldCodec(Codec elementCodec, String name) - { - this.elementCodec = elementCodec; - this.name = name; - } - - @Override - public Stream keys(DynamicOps ops) - { - return Stream.of(ops.createString(this.name)); - } - - @Override - public DataResult> decode(DynamicOps ops, MapLike input) - { - T value = input.get(name); - if(value == null) - return DataResult.success(Optional.empty()); - - return this.elementCodec.parse(ops, value).map(Optional::of); - } - - @Override - public RecordBuilder encode(Optional input, DynamicOps ops, RecordBuilder prefix) - { - if(input.isPresent()) - return prefix.add(this.name, this.elementCodec.encodeStart(ops, input.get())); - return prefix; - } - - @Override - public boolean equals(Object o) - { - if(this == o) return true; - if(o == null || getClass() != o.getClass()) return false; - PreservingOptionalFieldCodec that = (PreservingOptionalFieldCodec) o; - return Objects.equals(elementCodec, that.elementCodec) && Objects.equals(name, that.name); - } - - @Override - public int hashCode() - { - return Objects.hash(elementCodec, name); - } - - @Override - public String toString() - { - return "PreservingOptionalFieldCodec[" + name + ": " + elementCodec + ']'; - } -} diff --git a/src/main/java/com/mraof/minestuck/util/WorldEventUtil.java b/src/main/java/com/mraof/minestuck/util/WorldEventUtil.java deleted file mode 100644 index 4072cf60b3..0000000000 --- a/src/main/java/com/mraof/minestuck/util/WorldEventUtil.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.mraof.minestuck.util; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.world.level.LevelAccessor; -import net.minecraft.world.level.block.LevelEvent; - -public class WorldEventUtil -{ - public static void dispenserEffect(LevelAccessor level, BlockPos pos, Direction direction, boolean success) - { - level.levelEvent(success ? LevelEvent.SOUND_DISPENSER_DISPENSE : LevelEvent.SOUND_DISPENSER_FAIL, pos, 0); - if(success) - { - int i = direction.getStepX() + 1 + (direction.getStepZ() + 1) * 3; - level.levelEvent(LevelEvent.PARTICLES_SHOOT_SMOKE, pos, i); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/mraof/minestuck/world/gen/feature/MesaFeature.java b/src/main/java/com/mraof/minestuck/world/gen/feature/MesaFeature.java index 19cbaa60ab..973ecceaca 100644 --- a/src/main/java/com/mraof/minestuck/world/gen/feature/MesaFeature.java +++ b/src/main/java/com/mraof/minestuck/world/gen/feature/MesaFeature.java @@ -147,7 +147,7 @@ private BlockPos generateMesa(BlockPos rockPos, int height, float plateauSize, L continue; } - if(!boundingBox.isInside(new BlockPos(entry.pos.x, 64, entry.pos.z)) || !checkCoord(entry.pos, heightMap)) + if(!boundingBox.isInside(entry.pos.atY(64)) || !checkCoord(entry.pos, heightMap)) continue; if(random.nextFloat() < entry.spreadChance) { @@ -158,7 +158,7 @@ private BlockPos generateMesa(BlockPos rockPos, int height, float plateauSize, L entry.spreadChance -= Math.min(0.5F, (2F*h)/height); if(!heightMap.containsKey(coord)) { - BlockPos pos = new BlockPos(coord.x, rockPos.getY() - h, coord.z); + BlockPos pos = coord.atY(rockPos.getY() - h); /*if(provider.villageHandler.isPositionInStructure(world, pos) || provider.structureHandler.isPositionInStructure(world, pos)) TODO { stomps=true; @@ -170,13 +170,13 @@ private BlockPos generateMesa(BlockPos rockPos, int height, float plateauSize, L } } else entry.spreadChance += 0.5F; - if(!level.getBlockState(new BlockPos(entry.pos.x, rockPos.getY() - h - 1, entry.pos.z)).equals(groundBlock)) + if(!level.getBlockState(entry.pos.atY(rockPos.getY() - h - 1)).equals(groundBlock)) toProcess2.add(entry); } for(Map.Entry entry : heightMap.entrySet()) { - BlockPos pos = new BlockPos(entry.getKey().x, entry.getValue(), entry.getKey().z); + BlockPos pos = entry.getKey().atY(entry.getValue()); do { was.put(pos, level.getBlockState(pos)); @@ -193,7 +193,7 @@ private BlockPos generateMesa(BlockPos rockPos, int height, float plateauSize, L int blockCount = 0; for(int i1 = 0; i1 < 4; i1++) { - Integer coordsHeight = heightMap.get(new CoordPair(coords.x + (i1 % 2), coords.z + i1/2)); + Integer coordsHeight = heightMap.get(new CoordPair(coords.x() + (i1 % 2), coords.z() + i1/2)); if(coordsHeight != null && coordsHeight == rockPos.getY()) blockCount++; } @@ -204,7 +204,7 @@ private BlockPos generateMesa(BlockPos rockPos, int height, float plateauSize, L } } - BlockPos corePosition = new BlockPos(nodePos.x, rockPos.getY() + 1, nodePos.z); + BlockPos corePosition = nodePos.atY(rockPos.getY() + 1); if(stomps) { @@ -229,4 +229,4 @@ private BlockEntry(CoordPair pos, float spreadChance) this.spreadChance = spreadChance; } } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/world/gen/feature/RockSpikeFeature.java b/src/main/java/com/mraof/minestuck/world/gen/feature/RockSpikeFeature.java index 8a5b6a41d7..c9f776b6be 100644 --- a/src/main/java/com/mraof/minestuck/world/gen/feature/RockSpikeFeature.java +++ b/src/main/java/com/mraof/minestuck/world/gen/feature/RockSpikeFeature.java @@ -143,7 +143,7 @@ private BlockPos generateRock(BlockPos rockPos, int height, float plateauSize, L entry.spreadChance -= Math.min(0.5F, (2F*h)/height); if(!heightMap.containsKey(coord)) { - BlockPos pos = new BlockPos(coord.x, rockPos.getY() - h, coord.z); + BlockPos pos = coord.atY(rockPos.getY() - h); /*if(provider.villageHandler.isPositionInStructure(world, pos) || provider.structureHandler.isPositionInStructure(world, pos)) TODO { stomps=true; @@ -155,13 +155,13 @@ private BlockPos generateRock(BlockPos rockPos, int height, float plateauSize, L } } else entry.spreadChance += 0.5F; - if(!level.getBlockState(new BlockPos(entry.pos.x, rockPos.getY() - h - 1, entry.pos.z)).equals(ground)) + if(!level.getBlockState(entry.pos.atY(rockPos.getY() - h - 1)).equals(ground)) toProcess2.add(entry); } for(Map.Entry entry : heightMap.entrySet()) { - BlockPos pos = new BlockPos(entry.getKey().x, entry.getValue(), entry.getKey().z); + BlockPos pos = entry.getKey().atY(entry.getValue()); do { /*if(provider.villageHandler.isPositionInStructure(world, pos) || provider.structureHandler.isPositionInStructure(world, pos) || stomps==true) TODO @@ -183,7 +183,7 @@ private BlockPos generateRock(BlockPos rockPos, int height, float plateauSize, L int blockCount = 0; for(int i1 = 0; i1 < 4; i1++) { - Integer coordsHeight = heightMap.get(new CoordPair(coords.x + (i1 % 2), coords.z + i1/2)); + Integer coordsHeight = heightMap.get(new CoordPair(coords.x() + (i1 % 2), coords.z() + i1/2)); if(coordsHeight != null && coordsHeight == rockPos.getY()) blockCount++; } @@ -194,7 +194,7 @@ private BlockPos generateRock(BlockPos rockPos, int height, float plateauSize, L } } - BlockPos corePosition = new BlockPos(nodePos.x, rockPos.getY() + 1, nodePos.z); + BlockPos corePosition = nodePos.atY(rockPos.getY() + 1); if(stomps) { @@ -219,4 +219,4 @@ private BlockEntry(CoordPair pos, float spreadChance) this.spreadChance = spreadChance; } } -} \ No newline at end of file +} diff --git a/src/main/java/com/mraof/minestuck/world/lands/LandTypeExtensions.java b/src/main/java/com/mraof/minestuck/world/lands/LandTypeExtensions.java index e0f26ba593..651de564bf 100644 --- a/src/main/java/com/mraof/minestuck/world/lands/LandTypeExtensions.java +++ b/src/main/java/com/mraof/minestuck/world/lands/LandTypeExtensions.java @@ -9,7 +9,6 @@ import com.mojang.serialization.JsonOps; import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mraof.minestuck.Minestuck; -import com.mraof.minestuck.util.PreservingOptionalFieldCodec; import com.mraof.minestuck.world.biome.LandBiomeType; import com.mraof.minestuck.world.gen.LandChunkGenerator; import net.minecraft.MethodsReturnNonnullByDefault; @@ -23,6 +22,7 @@ import net.minecraft.server.packs.resources.Resource; import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.SimplePreparableReloadListener; +import net.minecraft.util.ExtraCodecs; import net.minecraft.util.profiling.ProfilerFiller; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.biome.MobSpawnSettings; @@ -238,9 +238,9 @@ public record ParsedExtension(List features, List CODEC = RecordCodecBuilder.create(instance -> instance.group( - PreservingOptionalFieldCodec.forList(FeatureExtension.CODEC.listOf(), "features").forGetter(ParsedExtension::features), - PreservingOptionalFieldCodec.forList(CarverExtension.CODEC.listOf(), "carvers").forGetter(ParsedExtension::carvers), - PreservingOptionalFieldCodec.forList(MobSpawnExtension.CODEC.listOf(), "mob_spawns").forGetter(ParsedExtension::mobSpawns) + ExtraCodecs.strictOptionalField(FeatureExtension.CODEC.listOf(), "features", Collections.emptyList()).forGetter(ParsedExtension::features), + ExtraCodecs.strictOptionalField(CarverExtension.CODEC.listOf(), "carvers", Collections.emptyList()).forGetter(ParsedExtension::carvers), + ExtraCodecs.strictOptionalField(MobSpawnExtension.CODEC.listOf(), "mob_spawns", Collections.emptyList()).forGetter(ParsedExtension::mobSpawns) ).apply(instance, ParsedExtension::new)); void addAllTo(ImmutableList.Builder builder) diff --git a/src/main/java/com/mraof/minestuck/world/storage/MSExtraData.java b/src/main/java/com/mraof/minestuck/world/storage/MSExtraData.java index 08cc177137..f6e5024251 100644 --- a/src/main/java/com/mraof/minestuck/world/storage/MSExtraData.java +++ b/src/main/java/com/mraof/minestuck/world/storage/MSExtraData.java @@ -6,6 +6,7 @@ import com.mraof.minestuck.entry.PostEntryTask; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.Tag; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; @@ -65,8 +66,8 @@ public static MSExtraData load(CompoundTag nbt) ListTag entryTaskList = nbt.getList("entry_tasks", Tag.TAG_COMPOUND); for(int i = 0; i < entryTaskList.size(); i++) { - CompoundTag tag = entryTaskList.getCompound(i); - data.postEntryTasks.add(new PostEntryTask(tag)); + PostEntryTask.CODEC.parse(NbtOps.INSTANCE, entryTaskList.getCompound(i)) + .resultOrPartial(LOGGER::error).ifPresent(data.postEntryTasks::add); } if(nbt.contains("card_captchas", Tag.TAG_COMPOUND)) @@ -85,7 +86,9 @@ public CompoundTag save(CompoundTag compound) compound.put("editmode_recovery", editRecoveryList); ListTag entryTaskList = new ListTag(); - entryTaskList.addAll(postEntryTasks.stream().map(PostEntryTask::write).toList()); + postEntryTasks.stream() + .flatMap(task -> PostEntryTask.CODEC.encodeStart(NbtOps.INSTANCE, task).resultOrPartial(LOGGER::error).stream()) + .forEach(entryTaskList::add); compound.put("entry_tasks", entryTaskList); @@ -209,4 +212,4 @@ public boolean isDirty() { return super.isDirty() || !activeEditData.isEmpty(); //Always save at every opportunity if editmode is active for someone } -} \ No newline at end of file +}