From 689375014d03c9bcba3614af33db50596179aeaa Mon Sep 17 00:00:00 2001 From: TheMCLoveMan Date: Thu, 21 Mar 2024 00:37:18 +0100 Subject: [PATCH] [24w11a] Initial port --- build.gradle | 26 +++-- gradle.properties | 18 ++-- .../themcbrothers/uselessmod/UselessMod.java | 2 + .../uselessmod/api/CoffeeType.java | 3 + .../client/model/MachineSupplierModel.java | 14 +-- .../client/model/WallClosetModel.java | 18 ++-- .../compat/VanillaCompatibility.java | 13 +-- .../data/UselessAdvancementProvider.java | 7 +- .../uselessmod/data/UselessDataGen.java | 4 +- .../data/UselessRecipeProvider.java | 7 +- .../data/loot/UselessBlockLoot.java | 41 ++++---- .../data/loot/UselessEntityLoot.java | 4 +- .../data/loot/UselessLootTableProvider.java | 6 +- .../data/worldgen/biome/UselessBiomeData.java | 4 +- .../worldgen/biome/UselessBiomeModifiers.java | 6 +- .../uselessmod/init/ModArmorMaterials.java | 94 ------------------- .../uselessmod/init/ModBlocks.java | 6 +- .../uselessmod/init/ModItems.java | 36 +++---- .../uselessmod/init/Registration.java | 8 ++ .../init/UselessArmorMaterials.java | 61 ++++++++++++ .../init/UselessCreativeModeTabs.java | 16 ++-- .../init/UselessDataComponents.java | 44 +++++++++ .../uselessmod/init/UselessFluidTypes.java | 4 +- .../uselessmod/network/MessageProxy.java | 2 +- .../network/UselessPacketHandler.java | 6 +- .../packets/BlockEntitySyncPacket.java | 35 ++++--- .../CoffeeMachineMilkUpdatePacket.java | 27 +++--- .../packets/CoffeeMachineStartPacket.java | 27 +++--- .../uselessmod/setup/ClientSetup.java | 26 +---- .../uselessmod/util/CoffeeUtils.java | 17 +--- .../world/item/BucketWithPaintItem.java | 15 +-- .../uselessmod/world/item/CupBlockItem.java | 4 +- .../world/item/LightSwitchBlockItem.java | 28 +++--- .../uselessmod/world/item/PaintBrushItem.java | 21 ++--- .../world/item/crafting/CoffeeRecipe.java | 40 ++++---- .../crafting/LightSwitchConvertRecipe.java | 2 +- .../world/level/block/CoffeeMachineBlock.java | 11 ++- .../world/level/block/CupBlock.java | 6 +- .../world/level/block/LightSwitchBlock.java | 32 +------ .../level/block/LightSwitchBlockBlock.java | 11 --- .../level/block/MachineSupplierBlock.java | 38 +++----- .../world/level/block/PaintBucketBlock.java | 28 +++--- .../world/level/block/PaintedWoolBlock.java | 27 ++---- .../world/level/block/WallClosetBlock.java | 43 ++------- .../entity/CoffeeMachineBlockEntity.java | 66 ++++++++----- .../level/block/entity/CupBlockEntity.java | 37 ++++++-- .../block/entity/LightSwitchBlockEntity.java | 27 +++++- .../entity/MachineSupplierBlockEntity.java | 15 +-- .../block/entity/PaintBucketBlockEntity.java | 54 +++++++---- .../block/entity/PaintedWoolBlockEntity.java | 31 ++++-- .../block/entity/SyncableBlockEntity.java | 5 +- .../block/entity/WallClosetBlockEntity.java | 58 +++++++++--- .../world/worldgen/UselessOreFeatures.java | 4 +- .../world/worldgen/UselessOrePlacements.java | 4 +- .../world/worldgen/UselessTreeFeatures.java | 4 +- .../world/worldgen/UselessTreePlacements.java | 4 +- .../worldgen/UselessVegetationFeatures.java | 4 +- .../worldgen/UselessVegetationPlacements.java | 4 +- 58 files changed, 639 insertions(+), 566 deletions(-) delete mode 100644 src/main/java/net/themcbrothers/uselessmod/init/ModArmorMaterials.java create mode 100644 src/main/java/net/themcbrothers/uselessmod/init/UselessArmorMaterials.java create mode 100644 src/main/java/net/themcbrothers/uselessmod/init/UselessDataComponents.java diff --git a/build.gradle b/build.gradle index 5be0527a..868b3cc5 100644 --- a/build.gradle +++ b/build.gradle @@ -1,18 +1,13 @@ plugins { id 'idea' id 'maven-publish' - id 'net.neoforged.gradle.userdev' version '7.+' + id 'net.neoforged.gradle.userdev' version '7.0.100' id 'me.shedaniel.unified-publishing' version '0.1.+' } version = mod_version group = mod_group_id -repositories { - maven { url = "https://nexus.themcbrothers.net/repository/maven-mod-dependencies" } - mavenLocal() -} - base { archivesName = mod_id } @@ -67,6 +62,19 @@ runs { // Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } +repositories { + maven { url = "https://nexus.themcbrothers.net/repository/maven-mod-dependencies" } + mavenLocal() + + maven { + name 'Maven for PR #715' // https://github.com/neoforged/NeoForge/pull/715 + url 'https://prmaven.neoforged.net/NeoForge/pr715' + content { + includeModule('net.neoforged', 'neoforge') + } + } +} + dependencies { // NeoForge implementation "net.neoforged:neoforge:$neo_version" @@ -75,9 +83,9 @@ dependencies { implementation "net.themcbrothers:themcbroslib:$minecraft_version-$lib_version" // JEI - compileOnly("mezz.jei:jei-$minecraft_version-common-api:$jei_version") - compileOnly("mezz.jei:jei-$minecraft_version-neoforge-api:$jei_version") - runtimeOnly("mezz.jei:jei-$minecraft_version-neoforge:$jei_version") + compileOnly("mezz.jei:jei-1.20.4-common-api:$jei_version") + compileOnly("mezz.jei:jei-1.20.4-neoforge-api:$jei_version") +// runtimeOnly("mezz.jei:jei-1.20.4-neoforge:$jei_version") } tasks.named('processResources', ProcessResources).configure { diff --git a/gradle.properties b/gradle.properties index 5741bde8..1b42838a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,21 +5,21 @@ org.gradle.daemon=false org.gradle.debug=false # Version -mod_version=9.1.0 +mod_version=10.0.0-alpha artifact_type=release # Minecraft -minecraft_version=1.20.4 -minecraft_version_range=[1.20.4, 1.21) +minecraft_version=24w11a +minecraft_version_range=24w11a # NeoForge -neo_version=20.4.184 -neo_version_range=[20.4.167,) +neo_version=20.5.0-alpha.24w11a.20240318.171240 +neo_version_range=20.5.0-alpha.24w11a.20240318.171240 loader_version_range=[2,) # Mappings -neogradle.subsystems.parchment.minecraftVersion=1.20.3 -neogradle.subsystems.parchment.mappingsVersion=2023.12.31 +neogradle.subsystems.parchment.minecraftVersion=1.20.4 +neogradle.subsystems.parchment.mappingsVersion=2024.02.25 # Mod Properties mod_name=Useless Mod @@ -32,8 +32,8 @@ mod_license=MIT License catalogue_item_icon=uselessmod:useless_ingot # Dependencies -lib_version=6.1.0 -lib_version_range=[1.20.4-6.1.0,) +lib_version=7.0.0-SNAPSHOT +lib_version_range=24w11a-7.0.0-SNAPSHOT jei_version=17.3.0.49 # Publishing diff --git a/src/main/java/net/themcbrothers/uselessmod/UselessMod.java b/src/main/java/net/themcbrothers/uselessmod/UselessMod.java index 86b4f93c..ab49919c 100644 --- a/src/main/java/net/themcbrothers/uselessmod/UselessMod.java +++ b/src/main/java/net/themcbrothers/uselessmod/UselessMod.java @@ -1,8 +1,10 @@ package net.themcbrothers.uselessmod; +import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Blocks; import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.IEventBus; import net.neoforged.fml.ModContainer; diff --git a/src/main/java/net/themcbrothers/uselessmod/api/CoffeeType.java b/src/main/java/net/themcbrothers/uselessmod/api/CoffeeType.java index 128889c0..d1be2f18 100644 --- a/src/main/java/net/themcbrothers/uselessmod/api/CoffeeType.java +++ b/src/main/java/net/themcbrothers/uselessmod/api/CoffeeType.java @@ -1,5 +1,6 @@ package net.themcbrothers.uselessmod.api; +import com.mojang.serialization.Codec; import net.minecraft.Util; import net.minecraft.world.effect.MobEffectInstance; import org.jetbrains.annotations.Nullable; @@ -7,6 +8,8 @@ import java.util.Set; public class CoffeeType { + public static final Codec CODEC = UselessRegistries.COFFEE_REGISTRY.byNameCodec(); + private final Set effects; private final int color; private final boolean foil; diff --git a/src/main/java/net/themcbrothers/uselessmod/client/model/MachineSupplierModel.java b/src/main/java/net/themcbrothers/uselessmod/client/model/MachineSupplierModel.java index 4d4ee97a..bcdcd716 100644 --- a/src/main/java/net/themcbrothers/uselessmod/client/model/MachineSupplierModel.java +++ b/src/main/java/net/themcbrothers/uselessmod/client/model/MachineSupplierModel.java @@ -16,14 +16,9 @@ import net.minecraft.client.resources.model.ModelBaker; import net.minecraft.client.resources.model.ModelState; import net.minecraft.core.Direction; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtUtils; -import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; @@ -35,6 +30,7 @@ import net.neoforged.neoforge.client.model.geometry.IGeometryLoader; import net.neoforged.neoforge.client.model.geometry.IUnbakedGeometry; import net.themcbrothers.uselessmod.init.ModBlocks; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.world.level.block.entity.MachineSupplierBlockEntity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -128,13 +124,7 @@ private static class ItemOverrideHandler extends ItemOverrides { @Nullable @Override public BakedModel resolve(BakedModel model, ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, int i) { - CompoundTag tag = BlockItem.getBlockEntityData(stack); - BlockState mimic = null; - - if (level != null && tag != null && tag.contains("Mimic", Tag.TAG_COMPOUND)) { - mimic = NbtUtils.readBlockState(level.holderLookup(Registries.BLOCK), tag.getCompound("Mimic")); - } - + BlockState mimic = stack.get(UselessDataComponents.MIMIC.get()); return ((MachineSupplierModel) model).getMimicModel(mimic); } } diff --git a/src/main/java/net/themcbrothers/uselessmod/client/model/WallClosetModel.java b/src/main/java/net/themcbrothers/uselessmod/client/model/WallClosetModel.java index 2ab0b8a3..9a8e3764 100644 --- a/src/main/java/net/themcbrothers/uselessmod/client/model/WallClosetModel.java +++ b/src/main/java/net/themcbrothers/uselessmod/client/model/WallClosetModel.java @@ -21,13 +21,10 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.RandomSource; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.inventory.InventoryMenu; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockAndTintGetter; @@ -42,6 +39,7 @@ import net.neoforged.neoforge.client.model.geometry.IGeometryLoader; import net.neoforged.neoforge.client.model.geometry.IUnbakedGeometry; import net.themcbrothers.uselessmod.UselessMod; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.world.level.block.entity.WallClosetBlockEntity; import org.apache.commons.compress.utils.Lists; import org.jetbrains.annotations.NotNull; @@ -181,14 +179,16 @@ private static class ItemOverrideHandler extends ItemOverrides { @Nullable @Override public BakedModel resolve(BakedModel model, ItemStack stack, @Nullable ClientLevel level, @Nullable LivingEntity entity, int i) { - if (model instanceof WallClosetModel wallClosetModel) { - CompoundTag tag = BlockItem.getBlockEntityData(stack); - if (tag != null && tag.contains("Material", Tag.TAG_STRING)) { - final ResourceLocation key = ResourceLocation.tryParse(tag.getString("Material")); - final Block material = BuiltInRegistries.BLOCK.containsKey(key) ? BuiltInRegistries.BLOCK.get(key) : Blocks.OAK_PLANKS; - return wallClosetModel.getCustomModel(Objects.requireNonNull(material), Direction.NORTH); + if (model instanceof WallClosetModel wallClosetModel && stack.has(UselessDataComponents.WALL_CLOSET_MATERIAL.get())) { + Block material = stack.get(UselessDataComponents.WALL_CLOSET_MATERIAL.get()); + + if (material == null) { + material = Blocks.OAK_PLANKS; } + + return wallClosetModel.getCustomModel(Objects.requireNonNull(material), Direction.NORTH); } + return model; } } diff --git a/src/main/java/net/themcbrothers/uselessmod/compat/VanillaCompatibility.java b/src/main/java/net/themcbrothers/uselessmod/compat/VanillaCompatibility.java index eab4e17a..8f59c2f1 100644 --- a/src/main/java/net/themcbrothers/uselessmod/compat/VanillaCompatibility.java +++ b/src/main/java/net/themcbrothers/uselessmod/compat/VanillaCompatibility.java @@ -2,7 +2,7 @@ import com.google.common.collect.Maps; import net.minecraft.core.cauldron.CauldronInteraction; -import net.minecraft.world.InteractionResult; +import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.item.AxeItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.Block; @@ -11,6 +11,7 @@ import net.minecraft.world.level.block.LayeredCauldronBlock; import net.themcbrothers.uselessmod.init.ModBlocks; import net.themcbrothers.uselessmod.init.ModItems; +import net.themcbrothers.uselessmod.init.UselessDataComponents; public class VanillaCompatibility { public static void register() { @@ -52,20 +53,20 @@ public static void register() { LayeredCauldronBlock.lowerFillLevel(state, level, pos); } - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); }); CauldronInteraction.WATER.map().put(ModItems.PAINT_BRUSH.get(), (state, level, pos, player, hand, stack) -> { - if (stack.hasTag()) { + if (stack.has(UselessDataComponents.COLOR.get())) { if (!level.isClientSide) { - stack.getOrCreateTag().remove("Color"); + stack.remove(UselessDataComponents.COLOR.get()); LayeredCauldronBlock.lowerFillLevel(state, level, pos); } - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } - return InteractionResult.PASS; + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; }); } diff --git a/src/main/java/net/themcbrothers/uselessmod/data/UselessAdvancementProvider.java b/src/main/java/net/themcbrothers/uselessmod/data/UselessAdvancementProvider.java index 0b3bd342..2b9abe76 100644 --- a/src/main/java/net/themcbrothers/uselessmod/data/UselessAdvancementProvider.java +++ b/src/main/java/net/themcbrothers/uselessmod/data/UselessAdvancementProvider.java @@ -7,10 +7,13 @@ import net.minecraft.advancements.critereon.InventoryChangeTrigger; import net.minecraft.advancements.critereon.LocationPredicate; import net.minecraft.advancements.critereon.PlayerTrigger; +import net.minecraft.core.HolderGetter; import net.minecraft.core.HolderLookup; +import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; +import net.minecraft.world.level.biome.Biome; import net.neoforged.neoforge.common.data.AdvancementProvider; import net.neoforged.neoforge.common.data.ExistingFileHelper; import net.themcbrothers.uselessmod.UselessMod; @@ -27,9 +30,11 @@ public class UselessAdvancementProvider implements AdvancementProvider.AdvancementGenerator { @Override public void generate(HolderLookup.Provider registries, Consumer saver, ExistingFileHelper existingFileHelper) { + HolderGetter holderGetter = registries.lookupOrThrow(Registries.BIOME); + AdvancementHolder root = Advancement.Builder.advancement().display(info(ModItems.USELESS_INGOT, "root", rl("textures/gui/advancements/backgrounds/uselessmod.png"), AdvancementType.TASK, false, false, false)).addCriterion("what", InventoryChangeTrigger.TriggerInstance.hasItems(ModItems.USELESS_INGOT)).save(saver, rl("root"), existingFileHelper); Advancement.Builder.advancement().display(info(ModBlocks.USELESS_ORE, "mine_ore", null, AdvancementType.TASK, true, true, false)).parent(root).addCriterion("has_ingot", InventoryChangeTrigger.TriggerInstance.hasItems(ModItems.USELESS_INGOT)).save(saver, rl("mine_ore"), existingFileHelper); - AdvancementHolder biome = Advancement.Builder.advancement().display(info(ModBlocks.USELESS_OAK_SAPLING, "visit_useless_forest", null, AdvancementType.TASK, true, true, false)).parent(root).addCriterion("useless_forest", PlayerTrigger.TriggerInstance.located(LocationPredicate.Builder.inBiome(UselessBiomes.USELESS_FOREST))).save(saver, rl("visit_useless_forest"), existingFileHelper); + AdvancementHolder biome = Advancement.Builder.advancement().display(info(ModBlocks.USELESS_OAK_SAPLING, "visit_useless_forest", null, AdvancementType.TASK, true, true, false)).parent(root).addCriterion("useless_forest", PlayerTrigger.TriggerInstance.located(LocationPredicate.Builder.inBiome(holderGetter.getOrThrow(UselessBiomes.USELESS_FOREST)))).save(saver, rl("visit_useless_forest"), existingFileHelper); Advancement.Builder.advancement().display(info(ModBlocks.USELESS_ROSE, "collect_roses", null, AdvancementType.GOAL, true, true, false)).parent(biome).addCriterion("has_roses", InventoryChangeTrigger.TriggerInstance.hasItems(ModBlocks.RED_ROSE, ModBlocks.BLUE_ROSE, ModBlocks.USELESS_ROSE)).save(saver, rl("collect_roses"), existingFileHelper); } diff --git a/src/main/java/net/themcbrothers/uselessmod/data/UselessDataGen.java b/src/main/java/net/themcbrothers/uselessmod/data/UselessDataGen.java index 4209347b..de170dfb 100644 --- a/src/main/java/net/themcbrothers/uselessmod/data/UselessDataGen.java +++ b/src/main/java/net/themcbrothers/uselessmod/data/UselessDataGen.java @@ -48,10 +48,10 @@ public static void dataGen(final GatherDataEvent event) { .add(NeoForgeRegistries.Keys.BIOME_MODIFIERS, UselessBiomeModifiers::bootstrap); generator.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(packOutput, lookupProvider, registrySetBuilder, Set.of(UselessMod.MOD_ID))); - generator.addProvider(event.includeServer(), new UselessRecipeProvider(packOutput)); + generator.addProvider(event.includeServer(), new UselessRecipeProvider(packOutput, lookupProvider)); generator.addProvider(event.includeServer(), new UselessLanguageProvider(packOutput)); generator.addProvider(event.includeServer(), new AdvancementProvider(packOutput, lookupProvider, existingFileHelper, List.of(new UselessAdvancementProvider()))); - generator.addProvider(event.includeServer(), UselessLootTableProvider.create(packOutput)); + generator.addProvider(event.includeServer(), UselessLootTableProvider.create(packOutput, lookupProvider)); final BlockTagsProvider blockTagsProvider = new UselessTagsProvider.Blocks(packOutput, lookupProvider, existingFileHelper); generator.addProvider(event.includeServer(), blockTagsProvider); generator.addProvider(event.includeServer(), new UselessTagsProvider.Items(packOutput, lookupProvider, blockTagsProvider.contentsGetter(), existingFileHelper)); diff --git a/src/main/java/net/themcbrothers/uselessmod/data/UselessRecipeProvider.java b/src/main/java/net/themcbrothers/uselessmod/data/UselessRecipeProvider.java index 2cba9b23..417c311e 100644 --- a/src/main/java/net/themcbrothers/uselessmod/data/UselessRecipeProvider.java +++ b/src/main/java/net/themcbrothers/uselessmod/data/UselessRecipeProvider.java @@ -1,5 +1,6 @@ package net.themcbrothers.uselessmod.data; +import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.data.recipes.*; import net.minecraft.world.item.Items; @@ -19,11 +20,13 @@ import net.themcbrothers.uselessmod.world.item.crafting.LightSwitchConvertRecipe; import net.themcbrothers.uselessmod.world.item.crafting.PaintBrushDyeRecipe; +import java.util.concurrent.CompletableFuture; + import static net.themcbrothers.uselessmod.UselessMod.rl; public class UselessRecipeProvider extends RecipeProvider { - public UselessRecipeProvider(PackOutput packOutput) { - super(packOutput); + public UselessRecipeProvider(PackOutput packOutput, CompletableFuture lookupProvider) { + super(packOutput, lookupProvider); } @Override diff --git a/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessBlockLoot.java b/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessBlockLoot.java index 1466bec6..28f7cf51 100644 --- a/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessBlockLoot.java +++ b/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessBlockLoot.java @@ -1,9 +1,6 @@ package net.themcbrothers.uselessmod.data.loot; -import net.minecraft.advancements.critereon.EnchantmentPredicate; -import net.minecraft.advancements.critereon.ItemPredicate; -import net.minecraft.advancements.critereon.MinMaxBounds; -import net.minecraft.advancements.critereon.StatePropertiesPredicate; +import net.minecraft.advancements.critereon.*; import net.minecraft.core.Holder; import net.minecraft.data.loot.BlockLootSubProvider; import net.minecraft.world.flag.FeatureFlags; @@ -18,20 +15,21 @@ import net.minecraft.world.level.storage.loot.LootPool; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.entries.LootItem; +import net.minecraft.world.level.storage.loot.functions.CopyComponentsFunction; import net.minecraft.world.level.storage.loot.functions.CopyNameFunction; -import net.minecraft.world.level.storage.loot.functions.CopyNbtFunction; import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction; import net.minecraft.world.level.storage.loot.predicates.BonusLevelTableCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemBlockStatePropertyCondition; import net.minecraft.world.level.storage.loot.predicates.LootItemCondition; import net.minecraft.world.level.storage.loot.predicates.MatchTool; -import net.minecraft.world.level.storage.loot.providers.nbt.ContextNbtProvider; import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator; import net.neoforged.neoforge.common.Tags; import net.themcbrothers.uselessmod.init.ModItems; import net.themcbrothers.uselessmod.init.Registration; +import net.themcbrothers.uselessmod.init.UselessDataComponents; +import java.util.List; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -39,7 +37,13 @@ import static net.themcbrothers.uselessmod.init.ModBlocks.*; public class UselessBlockLoot extends BlockLootSubProvider { - private static final LootItemCondition.Builder HAS_SILK_TOUCH = MatchTool.toolMatches(ItemPredicate.Builder.item().hasEnchantment(new EnchantmentPredicate(Enchantments.SILK_TOUCH, MinMaxBounds.Ints.atLeast(1)))); + private static final LootItemCondition.Builder HAS_SILK_TOUCH = MatchTool.toolMatches( + ItemPredicate.Builder.item() + .withSubPredicate( + ItemSubPredicates.ENCHANTMENTS, + ItemEnchantmentsPredicate.enchantments(List.of(new EnchantmentPredicate(Enchantments.SILK_TOUCH, MinMaxBounds.Ints.atLeast(1)))) + ) + ); private static final LootItemCondition.Builder HAS_SHEARS = MatchTool.toolMatches(ItemPredicate.Builder.item().of(Tags.Items.SHEARS)); private static final LootItemCondition.Builder HAS_SHEARS_OR_SILK_TOUCH = HAS_SHEARS.or(HAS_SILK_TOUCH); private static final LootItemCondition.Builder HAS_NO_SHEARS_OR_SILK_TOUCH = HAS_SHEARS_OR_SILK_TOUCH.invert(); @@ -144,34 +148,37 @@ protected void generate() { private LootTable.Builder createCopyLightsDrop(ItemLike itemLike) { return LootTable.lootTable().withPool(applyExplosionCondition(itemLike, LootPool.lootPool() .setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(itemLike)) - .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Lights", "BlockEntityTag.Lights")))); + .apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY) + .copy(UselessDataComponents.LIGHTS.get())))); } private LootTable.Builder createCopyColorDrop(ItemLike itemLike) { return LootTable.lootTable().withPool(applyExplosionCondition(itemLike, LootPool.lootPool() .setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(itemLike)) - .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Color", "BlockEntityTag.Color")))); + .apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY) + .copy(UselessDataComponents.COLOR.get())))); } private LootTable.Builder mimicDrop(ItemLike itemLike) { return LootTable.lootTable().withPool(applyExplosionCondition(itemLike, LootPool.lootPool() .setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(itemLike)) - .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Mimic", "BlockEntityTag.Mimic")))); + .apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY) + .copy(UselessDataComponents.MIMIC.get())))); } private LootTable.Builder copyCoffeeDrop(ItemLike itemLike) { return LootTable.lootTable().withPool(applyExplosionCondition(itemLike, LootPool.lootPool() .setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(itemLike)) - .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY).copy("Coffee", "Coffee")))); + .apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY) + .copy(UselessDataComponents.COFFEE_TYPE.get())))); } private LootTable.Builder wallClosetDrop(Block block) { return LootTable.lootTable().withPool(applyExplosionCondition(block, LootPool.lootPool() .setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(block) .apply(CopyNameFunction.copyName(CopyNameFunction.NameSource.BLOCK_ENTITY)) - .apply(CopyNbtFunction.copyData(ContextNbtProvider.BLOCK_ENTITY) - .copy("Material", "BlockEntityTag.Material") - .copy("id", "BlockEntityTag.id"))))); + .apply(CopyComponentsFunction.copyComponents(CopyComponentsFunction.Source.BLOCK_ENTITY) + .copy(UselessDataComponents.WALL_CLOSET_MATERIAL.get()))))); } private LootTable.Builder createUselessLeavesDrop(Block leavesBlock, Block saplingBlock, float... chances) { @@ -181,18 +188,18 @@ private LootTable.Builder createUselessLeavesDrop(Block leavesBlock, Block sapli .add(LootItem.lootTableItem(leavesBlock) .when(HAS_SHEARS_OR_SILK_TOUCH) .otherwise(applyExplosionCondition(leavesBlock, LootItem.lootTableItem(saplingBlock)) - .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, chances))))) + .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.FORTUNE, chances))))) .withPool(LootPool.lootPool() .setRolls(ConstantValue.exactly(1.0F)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH) .add(applyExplosionDecay(leavesBlock, LootItem.lootTableItem(Items.STICK) .apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 2.0F)))) - .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, 0.02F, 0.022222223F, 0.025F, 0.033333335F, 0.1F)))) + .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.FORTUNE, 0.02F, 0.022222223F, 0.025F, 0.033333335F, 0.1F)))) .withPool(LootPool.lootPool() .setRolls(ConstantValue.exactly(1.0F)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH) .add(applyExplosionCondition(leavesBlock, LootItem.lootTableItem(Items.APPLE)) - .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, 0.005F, 0.0055555557F, 0.00625F, 0.008333334F, 0.025F)))); + .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.FORTUNE, 0.005F, 0.0055555557F, 0.00625F, 0.008333334F, 0.025F)))); } @Override diff --git a/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessEntityLoot.java b/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessEntityLoot.java index 3511ae0b..71806008 100644 --- a/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessEntityLoot.java +++ b/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessEntityLoot.java @@ -9,7 +9,7 @@ import net.minecraft.world.level.storage.loot.LootPool; import net.minecraft.world.level.storage.loot.LootTable; import net.minecraft.world.level.storage.loot.entries.LootItem; -import net.minecraft.world.level.storage.loot.entries.LootTableReference; +import net.minecraft.world.level.storage.loot.entries.NestedLootTable; import net.minecraft.world.level.storage.loot.functions.LootingEnchantFunction; import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction; import net.minecraft.world.level.storage.loot.functions.SmeltItemFunction; @@ -32,7 +32,7 @@ protected UselessEntityLoot() { @Override public void generate() { this.add(ModEntityTypes.USELESS_SHEEP.get(), LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(Items.MUTTON).apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 2.0F))).apply(SmeltItemFunction.smelted().when(LootItemEntityPropertyCondition.hasProperties(LootContext.EntityTarget.THIS, ENTITY_ON_FIRE))).apply(LootingEnchantFunction.lootingMultiplier(UniformGenerator.between(0.0F, 1.0F)))))); - this.add(ModEntityTypes.USELESS_SHEEP.get(), UselessLootTables.SHEEP_USELESS, LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.USELESS_WOOL))).withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootTableReference.lootTableReference(ModEntityTypes.USELESS_SHEEP.get().getDefaultLootTable())))); + this.add(ModEntityTypes.USELESS_SHEEP.get(), UselessLootTables.SHEEP_USELESS, LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModBlocks.USELESS_WOOL))).withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(NestedLootTable.lootTableReference(ModEntityTypes.USELESS_SHEEP.get().getDefaultLootTable())))); this.add(ModEntityTypes.USELESS_PIG.get(), LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(Items.PORKCHOP).apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 3.0F))).apply(SmeltItemFunction.smelted().when(LootItemEntityPropertyCondition.hasProperties(LootContext.EntityTarget.THIS, ENTITY_ON_FIRE))).apply(LootingEnchantFunction.lootingMultiplier(UniformGenerator.between(0.0F, 1.0F)))))); this.add(ModEntityTypes.USELESS_CHICKEN.get(), LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModItems.USELESS_FEATHER).apply(SetItemCountFunction.setCount(UniformGenerator.between(0.0F, 2.0F))).apply(LootingEnchantFunction.lootingMultiplier(UniformGenerator.between(0.0F, 1.0F))))).withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(Items.CHICKEN).apply(SmeltItemFunction.smelted().when(LootItemEntityPropertyCondition.hasProperties(LootContext.EntityTarget.THIS, ENTITY_ON_FIRE))).apply(LootingEnchantFunction.lootingMultiplier(UniformGenerator.between(0.0F, 1.0F)))))); this.add(ModEntityTypes.USELESS_COW.get(), LootTable.lootTable().withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(ModItems.USELESS_LEATHER).apply(SetItemCountFunction.setCount(UniformGenerator.between(0.0F, 2.0F))).apply(LootingEnchantFunction.lootingMultiplier(UniformGenerator.between(0.0F, 1.0F))))).withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)).add(LootItem.lootTableItem(Items.BEEF).apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 3.0F))).apply(SmeltItemFunction.smelted().when(LootItemEntityPropertyCondition.hasProperties(LootContext.EntityTarget.THIS, ENTITY_ON_FIRE))).apply(LootingEnchantFunction.lootingMultiplier(UniformGenerator.between(0.0F, 1.0F)))))); diff --git a/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessLootTableProvider.java b/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessLootTableProvider.java index e7307222..09be6051 100644 --- a/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessLootTableProvider.java +++ b/src/main/java/net/themcbrothers/uselessmod/data/loot/UselessLootTableProvider.java @@ -1,14 +1,16 @@ package net.themcbrothers.uselessmod.data.loot; +import net.minecraft.core.HolderLookup; import net.minecraft.data.PackOutput; import net.minecraft.data.loot.LootTableProvider; import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets; import java.util.Collections; import java.util.List; +import java.util.concurrent.CompletableFuture; public class UselessLootTableProvider { - public static LootTableProvider create(PackOutput output) { - return new LootTableProvider(output, Collections.emptySet(), List.of(new LootTableProvider.SubProviderEntry(UselessBlockLoot::new, LootContextParamSets.BLOCK), new LootTableProvider.SubProviderEntry(UselessEntityLoot::new, LootContextParamSets.ENTITY))); + public static LootTableProvider create(PackOutput output, CompletableFuture lookupProvider) { + return new LootTableProvider(output, Collections.emptySet(), List.of(new LootTableProvider.SubProviderEntry(UselessBlockLoot::new, LootContextParamSets.BLOCK), new LootTableProvider.SubProviderEntry(UselessEntityLoot::new, LootContextParamSets.ENTITY)), lookupProvider); } } diff --git a/src/main/java/net/themcbrothers/uselessmod/data/worldgen/biome/UselessBiomeData.java b/src/main/java/net/themcbrothers/uselessmod/data/worldgen/biome/UselessBiomeData.java index 82a671fc..2fa14ad1 100644 --- a/src/main/java/net/themcbrothers/uselessmod/data/worldgen/biome/UselessBiomeData.java +++ b/src/main/java/net/themcbrothers/uselessmod/data/worldgen/biome/UselessBiomeData.java @@ -3,7 +3,7 @@ import net.minecraft.core.HolderGetter; import net.minecraft.core.registries.Registries; import net.minecraft.data.worldgen.BiomeDefaultFeatures; -import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.world.entity.MobCategory; import net.minecraft.world.level.biome.*; import net.minecraft.world.level.levelgen.GenerationStep; @@ -14,7 +14,7 @@ import net.themcbrothers.uselessmod.world.worldgen.UselessVegetationPlacements; public final class UselessBiomeData { - public static void bootstrap(BootstapContext context) { + public static void bootstrap(BootstrapContext context) { HolderGetter placedFeatures = context.lookup(Registries.PLACED_FEATURE); HolderGetter> configuredCarvers = context.lookup(Registries.CONFIGURED_CARVER); diff --git a/src/main/java/net/themcbrothers/uselessmod/data/worldgen/biome/UselessBiomeModifiers.java b/src/main/java/net/themcbrothers/uselessmod/data/worldgen/biome/UselessBiomeModifiers.java index 8c1bd1bf..82d01c3d 100644 --- a/src/main/java/net/themcbrothers/uselessmod/data/worldgen/biome/UselessBiomeModifiers.java +++ b/src/main/java/net/themcbrothers/uselessmod/data/worldgen/biome/UselessBiomeModifiers.java @@ -3,7 +3,7 @@ import net.minecraft.core.HolderGetter; import net.minecraft.core.HolderSet; import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BiomeTags; @@ -16,7 +16,7 @@ import net.themcbrothers.uselessmod.world.worldgen.UselessOrePlacements; public final class UselessBiomeModifiers { - public static void bootstrap(BootstapContext context) { + public static void bootstrap(BootstrapContext context) { HolderGetter biomeGetter = context.lookup(Registries.BIOME); HolderGetter placedFeatures = context.lookup(Registries.PLACED_FEATURE); HolderSet overworldBiomes = biomeGetter.getOrThrow(BiomeTags.IS_OVERWORLD); @@ -32,7 +32,7 @@ public static void bootstrap(BootstapContext context) { registerOreModifier(context, placedFeatures, UselessOrePlacements.ORE_SUPER_USELESS_END, endBiomes); } - private static void registerOreModifier(BootstapContext context, HolderGetter placedFeatures, ResourceKey key, HolderSet biomes) { + private static void registerOreModifier(BootstrapContext context, HolderGetter placedFeatures, ResourceKey key, HolderSet biomes) { BiomeModifiers.AddFeaturesBiomeModifier modifier = new BiomeModifiers.AddFeaturesBiomeModifier(biomes, HolderSet.direct(placedFeatures.getOrThrow(key)), GenerationStep.Decoration.UNDERGROUND_ORES); context.register(ResourceKey.create(NeoForgeRegistries.Keys.BIOME_MODIFIERS, new ResourceLocation(key.location() + "_generation")), modifier); } diff --git a/src/main/java/net/themcbrothers/uselessmod/init/ModArmorMaterials.java b/src/main/java/net/themcbrothers/uselessmod/init/ModArmorMaterials.java deleted file mode 100644 index bd5cfd07..00000000 --- a/src/main/java/net/themcbrothers/uselessmod/init/ModArmorMaterials.java +++ /dev/null @@ -1,94 +0,0 @@ -package net.themcbrothers.uselessmod.init; - -import net.minecraft.Util; -import net.minecraft.sounds.SoundEvent; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.world.item.ArmorItem; -import net.minecraft.world.item.ArmorMaterial; -import net.minecraft.world.item.crafting.Ingredient; -import net.themcbrothers.uselessmod.UselessTags; - -import java.util.EnumMap; -import java.util.function.Supplier; - -public enum ModArmorMaterials implements ArmorMaterial { - USELESS("uselessmod:useless", 20, Util.make(new EnumMap<>(ArmorItem.Type.class), map -> { - map.put(ArmorItem.Type.BOOTS, 3); - map.put(ArmorItem.Type.LEGGINGS, 6); - map.put(ArmorItem.Type.CHESTPLATE, 7); - map.put(ArmorItem.Type.HELMET, 3); - }), 11, SoundEvents.ARMOR_EQUIP_IRON, 0.25F, 0.01F, () -> Ingredient.of(UselessTags.Items.INGOTS_USELESS)), - SUPER_USELESS("uselessmod:super_useless", 20, Util.make(new EnumMap<>(ArmorItem.Type.class), map -> { - map.put(ArmorItem.Type.BOOTS, 3); - map.put(ArmorItem.Type.LEGGINGS, 6); - map.put(ArmorItem.Type.CHESTPLATE, 7); - map.put(ArmorItem.Type.HELMET, 3); - }), 11, SoundEvents.ARMOR_EQUIP_IRON, 0.25F, 0.025F, () -> Ingredient.of(UselessTags.Items.INGOTS_SUPER_USELESS)); - - private static final EnumMap HEALTH_FUNCTION_FOR_TYPE = Util.make(new EnumMap<>(ArmorItem.Type.class), map -> { - map.put(ArmorItem.Type.BOOTS, 13); - map.put(ArmorItem.Type.LEGGINGS, 15); - map.put(ArmorItem.Type.CHESTPLATE, 16); - map.put(ArmorItem.Type.HELMET, 11); - }); - - private final String name; - private final int durabilityMultiplier; - private final EnumMap protectionFunctionForType; - private final int enchantmentValue; - private final SoundEvent sound; - private final float toughness; - private final float knockbackResistance; - private final Supplier repairIngredient; - - ModArmorMaterials(String name, int durabilityMultiplier, EnumMap protectionFunctionForType, int enchantmentValue, SoundEvent sound, float toughness, float knockbackResistance, Supplier repairIngredient) { - this.name = name; - this.durabilityMultiplier = durabilityMultiplier; - this.protectionFunctionForType = protectionFunctionForType; - this.enchantmentValue = enchantmentValue; - this.sound = sound; - this.toughness = toughness; - this.knockbackResistance = knockbackResistance; - this.repairIngredient = repairIngredient; - } - - @Override - public int getDurabilityForType(ArmorItem.Type type) { - return HEALTH_FUNCTION_FOR_TYPE.get(type) * this.durabilityMultiplier; - } - - @Override - public int getDefenseForType(ArmorItem.Type type) { - return this.protectionFunctionForType.get(type); - } - - @Override - public int getEnchantmentValue() { - return this.enchantmentValue; - } - - @Override - public SoundEvent getEquipSound() { - return this.sound; - } - - @Override - public Ingredient getRepairIngredient() { - return this.repairIngredient.get(); - } - - @Override - public String getName() { - return this.name; - } - - @Override - public float getToughness() { - return this.toughness; - } - - @Override - public float getKnockbackResistance() { - return this.knockbackResistance; - } -} diff --git a/src/main/java/net/themcbrothers/uselessmod/init/ModBlocks.java b/src/main/java/net/themcbrothers/uselessmod/init/ModBlocks.java index 6a2b8628..8e418cce 100644 --- a/src/main/java/net/themcbrothers/uselessmod/init/ModBlocks.java +++ b/src/main/java/net/themcbrothers/uselessmod/init/ModBlocks.java @@ -50,9 +50,9 @@ static void register() { public static final DeferredBlock SUPER_USELESS_TRAPDOOR = BLOCKS.register("super_useless_trapdoor", () -> new TrapDoorBlock(BlockSetType.IRON, ofFullCopy(Blocks.IRON_TRAPDOOR)), GENERAL_BLOCK_ITEM); // Natural - public static final DeferredBlock RED_ROSE = BLOCKS.register("red_rose", () -> new FlowerBlock(() -> MobEffects.NIGHT_VISION, 5, ofFullCopy(Blocks.POPPY)), GENERAL_BLOCK_ITEM); - public static final DeferredBlock BLUE_ROSE = BLOCKS.register("blue_rose", () -> new FlowerBlock(() -> MobEffects.SATURATION, 7, ofFullCopy(Blocks.POPPY)), GENERAL_BLOCK_ITEM); - public static final DeferredBlock USELESS_ROSE = BLOCKS.register("useless_rose", () -> new FlowerBlock(() -> MobEffects.LUCK, 2, ofFullCopy(Blocks.POPPY)), GENERAL_BLOCK_ITEM); + public static final DeferredBlock RED_ROSE = BLOCKS.register("red_rose", () -> new FlowerBlock(MobEffects.NIGHT_VISION, 5, ofFullCopy(Blocks.POPPY)), GENERAL_BLOCK_ITEM); + public static final DeferredBlock BLUE_ROSE = BLOCKS.register("blue_rose", () -> new FlowerBlock(MobEffects.SATURATION, 7, ofFullCopy(Blocks.POPPY)), GENERAL_BLOCK_ITEM); + public static final DeferredBlock USELESS_ROSE = BLOCKS.register("useless_rose", () -> new FlowerBlock(MobEffects.LUCK, 2, ofFullCopy(Blocks.POPPY)), GENERAL_BLOCK_ITEM); public static final DeferredBlock USELESS_OAK_SAPLING = BLOCKS.register("useless_oak_sapling", () -> new SaplingBlock(UselessOakTreeGrower.USELESS_OAK_TREE_GROWER, ofFullCopy(Blocks.OAK_SAPLING)), GENERAL_BLOCK_ITEM); public static final DeferredBlock USELESS_OAK_LEAVES = BLOCKS.register("useless_oak_leaves", () -> new LeavesBlock(ofFullCopy(Blocks.OAK_LEAVES)), GENERAL_BLOCK_ITEM); public static final DeferredBlock USELESS_OAK_LOG = BLOCKS.register("useless_oak_log", () -> new RotatedPillarBlock(ofFullCopy(Blocks.OAK_LOG)), GENERAL_BLOCK_ITEM); diff --git a/src/main/java/net/themcbrothers/uselessmod/init/ModItems.java b/src/main/java/net/themcbrothers/uselessmod/init/ModItems.java index e78aa8a9..ff07c415 100644 --- a/src/main/java/net/themcbrothers/uselessmod/init/ModItems.java +++ b/src/main/java/net/themcbrothers/uselessmod/init/ModItems.java @@ -29,29 +29,29 @@ static void register() { // Weapons and Tools public static final DeferredItem USELESS_SHEARS = ITEMS.register("useless_shears", () -> new ShearsItem(new Item.Properties().durability(320))); public static final DeferredItem USELESS_SHIELD = ITEMS.register("useless_shield", () -> new UselessShieldItem(ModTiers.USELESS, new Item.Properties().durability(420))); - public static final DeferredItem USELESS_SWORD = ITEMS.register("useless_sword", () -> new SwordItem(ModTiers.USELESS, 3, -2.4F, new Item.Properties())); - public static final DeferredItem USELESS_SHOVEL = ITEMS.register("useless_shovel", () -> new ShovelItem(ModTiers.USELESS, 1.5F, -3.0F, new Item.Properties())); - public static final DeferredItem USELESS_PICKAXE = ITEMS.register("useless_pickaxe", () -> new PickaxeItem(ModTiers.USELESS, 1, -2.8F, new Item.Properties())); - public static final DeferredItem USELESS_AXE = ITEMS.register("useless_axe", () -> new AxeItem(ModTiers.USELESS, 6.0F, -3.1F, new Item.Properties())); - public static final DeferredItem USELESS_HOE = ITEMS.register("useless_hoe", () -> new HoeItem(ModTiers.USELESS, -2, -1.0F, new Item.Properties())); + public static final DeferredItem USELESS_SWORD = ITEMS.register("useless_sword", () -> new SwordItem(ModTiers.USELESS, new Item.Properties().attributes(SwordItem.createAttributes(ModTiers.USELESS, 3, -2.4F)))); + public static final DeferredItem USELESS_SHOVEL = ITEMS.register("useless_shovel", () -> new ShovelItem(ModTiers.USELESS, new Item.Properties().attributes(ShovelItem.createAttributes(ModTiers.USELESS, 1.5F, -3.0F)))); + public static final DeferredItem USELESS_PICKAXE = ITEMS.register("useless_pickaxe", () -> new PickaxeItem(ModTiers.USELESS, new Item.Properties().attributes(PickaxeItem.createAttributes(ModTiers.USELESS, 1, -2.8F)))); + public static final DeferredItem USELESS_AXE = ITEMS.register("useless_axe", () -> new AxeItem(ModTiers.USELESS, new Item.Properties().attributes(AxeItem.createAttributes(ModTiers.USELESS, 6.0F, -3.1F)))); + public static final DeferredItem USELESS_HOE = ITEMS.register("useless_hoe", () -> new HoeItem(ModTiers.USELESS, new Item.Properties().attributes(HoeItem.createAttributes(ModTiers.USELESS, -2, -1.0F)))); public static final DeferredItem SUPER_USELESS_SHIELD = ITEMS.register("super_useless_shield", () -> new UselessShieldItem(ModTiers.SUPER_USELESS, new Item.Properties().durability(640))); - public static final DeferredItem SUPER_USELESS_SWORD = ITEMS.register("super_useless_sword", () -> new SwordItem(ModTiers.SUPER_USELESS, 3, -2.4F, new Item.Properties())); - public static final DeferredItem SUPER_USELESS_SHOVEL = ITEMS.register("super_useless_shovel", () -> new ShovelItem(ModTiers.SUPER_USELESS, 1.5F, -3.0F, new Item.Properties())); - public static final DeferredItem SUPER_USELESS_PICKAXE = ITEMS.register("super_useless_pickaxe", () -> new PickaxeItem(ModTiers.SUPER_USELESS, 1, -2.8F, new Item.Properties())); - public static final DeferredItem SUPER_USELESS_AXE = ITEMS.register("super_useless_axe", () -> new AxeItem(ModTiers.SUPER_USELESS, 6.0F, -3.1F, new Item.Properties())); - public static final DeferredItem SUPER_USELESS_HOE = ITEMS.register("super_useless_hoe", () -> new HoeItem(ModTiers.SUPER_USELESS, -2, -1.0F, new Item.Properties())); + public static final DeferredItem SUPER_USELESS_SWORD = ITEMS.register("super_useless_sword", () -> new SwordItem(ModTiers.SUPER_USELESS, new Item.Properties().attributes(SwordItem.createAttributes(ModTiers.SUPER_USELESS, 3, -2.4F)))); + public static final DeferredItem SUPER_USELESS_SHOVEL = ITEMS.register("super_useless_shovel", () -> new ShovelItem(ModTiers.SUPER_USELESS, new Item.Properties().attributes(ShovelItem.createAttributes(ModTiers.SUPER_USELESS, 1.5F, -3.0F)))); + public static final DeferredItem SUPER_USELESS_PICKAXE = ITEMS.register("super_useless_pickaxe", () -> new PickaxeItem(ModTiers.SUPER_USELESS, new Item.Properties().attributes(PickaxeItem.createAttributes(ModTiers.SUPER_USELESS, 1, -2.8F)))); + public static final DeferredItem SUPER_USELESS_AXE = ITEMS.register("super_useless_axe", () -> new AxeItem(ModTiers.SUPER_USELESS, new Item.Properties().attributes(AxeItem.createAttributes(ModTiers.SUPER_USELESS, 6.0F, -3.1F)))); + public static final DeferredItem SUPER_USELESS_HOE = ITEMS.register("super_useless_hoe", () -> new HoeItem(ModTiers.SUPER_USELESS, new Item.Properties().attributes(HoeItem.createAttributes(ModTiers.SUPER_USELESS, -2, -1.0F)))); // Armor public static final DeferredItem USELESS_ELYTRA = ITEMS.register("useless_elytra", () -> new UselessElytraItem(new Item.Properties().durability(540).rarity(Rarity.UNCOMMON))); - public static final DeferredItem USELESS_HELMET = ITEMS.register("useless_helmet", () -> new ArmorItem(ModArmorMaterials.USELESS, ArmorItem.Type.HELMET, new Item.Properties())); - public static final DeferredItem USELESS_CHESTPLATE = ITEMS.register("useless_chestplate", () -> new ArmorItem(ModArmorMaterials.USELESS, ArmorItem.Type.CHESTPLATE, new Item.Properties())); - public static final DeferredItem USELESS_LEGGINGS = ITEMS.register("useless_leggings", () -> new ArmorItem(ModArmorMaterials.USELESS, ArmorItem.Type.LEGGINGS, new Item.Properties())); - public static final DeferredItem USELESS_BOOTS = ITEMS.register("useless_boots", () -> new ArmorItem(ModArmorMaterials.USELESS, ArmorItem.Type.BOOTS, new Item.Properties())); + public static final DeferredItem USELESS_HELMET = ITEMS.register("useless_helmet", () -> new ArmorItem(UselessArmorMaterials.USELESS, ArmorItem.Type.HELMET, new Item.Properties().defaultDurability(ArmorItem.Type.CHESTPLATE.getDurability(20)))); + public static final DeferredItem USELESS_CHESTPLATE = ITEMS.register("useless_chestplate", () -> new ArmorItem(UselessArmorMaterials.USELESS, ArmorItem.Type.CHESTPLATE, new Item.Properties().defaultDurability(ArmorItem.Type.CHESTPLATE.getDurability(20)))); + public static final DeferredItem USELESS_LEGGINGS = ITEMS.register("useless_leggings", () -> new ArmorItem(UselessArmorMaterials.USELESS, ArmorItem.Type.LEGGINGS, new Item.Properties().defaultDurability(ArmorItem.Type.CHESTPLATE.getDurability(20)))); + public static final DeferredItem USELESS_BOOTS = ITEMS.register("useless_boots", () -> new ArmorItem(UselessArmorMaterials.USELESS, ArmorItem.Type.BOOTS, new Item.Properties().defaultDurability(ArmorItem.Type.CHESTPLATE.getDurability(20)))); public static final DeferredItem SUPER_USELESS_ELYTRA = ITEMS.register("super_useless_elytra", () -> new UselessElytraItem(new Item.Properties().durability(864).rarity(Rarity.UNCOMMON))); - public static final DeferredItem SUPER_USELESS_HELMET = ITEMS.register("super_useless_helmet", () -> new ArmorItem(ModArmorMaterials.SUPER_USELESS, ArmorItem.Type.HELMET, new Item.Properties())); - public static final DeferredItem SUPER_USELESS_CHESTPLATE = ITEMS.register("super_useless_chestplate", () -> new ArmorItem(ModArmorMaterials.SUPER_USELESS, ArmorItem.Type.CHESTPLATE, new Item.Properties())); - public static final DeferredItem SUPER_USELESS_LEGGINGS = ITEMS.register("super_useless_leggings", () -> new ArmorItem(ModArmorMaterials.SUPER_USELESS, ArmorItem.Type.LEGGINGS, new Item.Properties())); - public static final DeferredItem SUPER_USELESS_BOOTS = ITEMS.register("super_useless_boots", () -> new ArmorItem(ModArmorMaterials.SUPER_USELESS, ArmorItem.Type.BOOTS, new Item.Properties())); + public static final DeferredItem SUPER_USELESS_HELMET = ITEMS.register("super_useless_helmet", () -> new ArmorItem(UselessArmorMaterials.SUPER_USELESS, ArmorItem.Type.HELMET, new Item.Properties().defaultDurability(ArmorItem.Type.CHESTPLATE.getDurability(22)))); + public static final DeferredItem SUPER_USELESS_CHESTPLATE = ITEMS.register("super_useless_chestplate", () -> new ArmorItem(UselessArmorMaterials.SUPER_USELESS, ArmorItem.Type.CHESTPLATE, new Item.Properties().defaultDurability(ArmorItem.Type.CHESTPLATE.getDurability(22)))); + public static final DeferredItem SUPER_USELESS_LEGGINGS = ITEMS.register("super_useless_leggings", () -> new ArmorItem(UselessArmorMaterials.SUPER_USELESS, ArmorItem.Type.LEGGINGS, new Item.Properties().defaultDurability(ArmorItem.Type.CHESTPLATE.getDurability(22)))); + public static final DeferredItem SUPER_USELESS_BOOTS = ITEMS.register("super_useless_boots", () -> new ArmorItem(UselessArmorMaterials.SUPER_USELESS, ArmorItem.Type.BOOTS, new Item.Properties().defaultDurability(ArmorItem.Type.CHESTPLATE.getDurability(22)))); public static final DeferredItem USELESS_SKELETON_SKULL = ITEMS.register("useless_skeleton_skull", () -> new StandingAndWallBlockItem(ModBlocks.USELESS_SKELETON_SKULL.get(), ModBlocks.USELESS_SKELETON_WALL_SKULL.get(), new Item.Properties().rarity(Rarity.UNCOMMON), Direction.DOWN)); diff --git a/src/main/java/net/themcbrothers/uselessmod/init/Registration.java b/src/main/java/net/themcbrothers/uselessmod/init/Registration.java index a1c516b3..425a3919 100644 --- a/src/main/java/net/themcbrothers/uselessmod/init/Registration.java +++ b/src/main/java/net/themcbrothers/uselessmod/init/Registration.java @@ -1,8 +1,10 @@ package net.themcbrothers.uselessmod.init; +import net.minecraft.core.component.DataComponentType; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.decoration.PaintingVariant; +import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.item.crafting.RecipeType; @@ -31,6 +33,8 @@ public final class Registration { public static final DeferredRegister FLUID_TYPES = DeferredRegister.create(NeoForgeRegistries.Keys.FLUID_TYPES, UselessMod.MOD_ID); public static final DeferredRegister FLUIDS = DeferredRegister.create(Registries.FLUID, UselessMod.MOD_ID); public static final DeferredRegister CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, UselessMod.MOD_ID); + public static final DeferredRegister> DATA_COMPONENT_TYPES = DeferredRegister.create(Registries.DATA_COMPONENT_TYPE, UselessMod.MOD_ID); + public static final DeferredRegister ARMOR_MATERIALS = DeferredRegister.create(Registries.ARMOR_MATERIAL, UselessMod.MOD_ID); public static void register(IEventBus bus) { bus.addListener(NewRegistryEvent.class, event -> event.register(UselessRegistries.COFFEE_REGISTRY)); @@ -48,6 +52,8 @@ public static void register(IEventBus bus) { UselessFluidTypes.register(); UselessFluids.register(); UselessCreativeModeTabs.register(); + UselessDataComponents.register(); + UselessArmorMaterials.register(); BLOCKS.register(bus); ITEMS.register(bus); @@ -62,6 +68,8 @@ public static void register(IEventBus bus) { FLUID_TYPES.register(bus); FLUIDS.register(bus); CREATIVE_MODE_TABS.register(bus); + DATA_COMPONENT_TYPES.register(bus); + ARMOR_MATERIALS.register(bus); } private Registration() { diff --git a/src/main/java/net/themcbrothers/uselessmod/init/UselessArmorMaterials.java b/src/main/java/net/themcbrothers/uselessmod/init/UselessArmorMaterials.java new file mode 100644 index 00000000..14f5f376 --- /dev/null +++ b/src/main/java/net/themcbrothers/uselessmod/init/UselessArmorMaterials.java @@ -0,0 +1,61 @@ +package net.themcbrothers.uselessmod.init; + +import net.minecraft.Util; +import net.minecraft.core.Holder; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.item.ArmorItem; +import net.minecraft.world.item.ArmorMaterial; +import net.minecraft.world.item.crafting.Ingredient; +import net.themcbrothers.uselessmod.UselessTags; + +import java.util.EnumMap; +import java.util.List; +import java.util.function.Supplier; + +public final class UselessArmorMaterials { + static void register() { + } + + public static final Holder USELESS = register("useless", + Util.make(new EnumMap<>(ArmorItem.Type.class), map -> { + map.put(ArmorItem.Type.BOOTS, 3); + map.put(ArmorItem.Type.LEGGINGS, 6); + map.put(ArmorItem.Type.CHESTPLATE, 7); + map.put(ArmorItem.Type.HELMET, 3); + }), + 11, + SoundEvents.ARMOR_EQUIP_IRON, + 0.25F, 0.01F, + () -> Ingredient.of(UselessTags.Items.INGOTS_USELESS) + ); + + public static final Holder SUPER_USELESS = register("super_useless", + Util.make(new EnumMap<>(ArmorItem.Type.class), map -> { + map.put(ArmorItem.Type.BOOTS, 3); + map.put(ArmorItem.Type.LEGGINGS, 6); + map.put(ArmorItem.Type.CHESTPLATE, 7); + map.put(ArmorItem.Type.HELMET, 3); + }), + 11, + SoundEvents.ARMOR_EQUIP_IRON, + 0.25F, 0.025F, + () -> Ingredient.of(UselessTags.Items.INGOTS_SUPER_USELESS) + ); + + @SuppressWarnings("SameParameterValue") + private static Holder register( + String name, + EnumMap defense, + int enchantmentValue, + Holder equipSound, + float toughness, + float knockbackResistance, + Supplier repairIngredient + ) { + List layers = List.of(new ArmorMaterial.Layer(new ResourceLocation(name))); + return Registration.ARMOR_MATERIALS.register(name, () -> + new ArmorMaterial(defense, enchantmentValue, equipSound, repairIngredient, layers, toughness, knockbackResistance)); + } +} diff --git a/src/main/java/net/themcbrothers/uselessmod/init/UselessCreativeModeTabs.java b/src/main/java/net/themcbrothers/uselessmod/init/UselessCreativeModeTabs.java index a990615b..ed8f3498 100644 --- a/src/main/java/net/themcbrothers/uselessmod/init/UselessCreativeModeTabs.java +++ b/src/main/java/net/themcbrothers/uselessmod/init/UselessCreativeModeTabs.java @@ -61,7 +61,7 @@ static void buildCreativeTab(final BuildCreativeModeTabContentsEvent event) { if (event.getTab() == MAIN_TAB.get()) { NonNullList itemStacks = NonNullList.create(); - Registration.BLOCKS.getEntries().stream().map(Holder::value).map(UselessCreativeModeTabs::convert).forEach(itemStacks::addAll); +// Registration.BLOCKS.getEntries().stream().map(Holder::value).map(UselessCreativeModeTabs::convert).forEach(itemStacks::addAll); Registration.ITEMS.getEntries().stream().map(Holder::value).map(UselessCreativeModeTabs::convert).forEach(itemStacks::addAll); // remove some items @@ -83,17 +83,16 @@ static void buildCreativeTab(final BuildCreativeModeTabContentsEvent event) { for (DyeColor color : DyeColor.values()) { // painted wool final ItemStack stackWool = new ItemStack(ModBlocks.PAINTED_WOOL); - CompoundTag tag = getTagWithColorFromDyeColor(color); - BlockItem.setBlockEntityData(stackWool, ModBlockEntityTypes.PAINTED_WOOL.get(), tag); + applyColorComponentToStack(stackWool, color); // paint brush final ItemStack stackBrush = new ItemStack(ModItems.PAINT_BRUSH.value()); - stackBrush.setTag(getTagWithColorFromDyeColor(color)); + applyColorComponentToStack(stackBrush, color); stackBrush.setDamageValue(0); // bucket with paint final ItemStack stackBucket = new ItemStack(ModItems.BUCKET_PAINT.value()); - stackBucket.setTag(getTagWithColorFromDyeColor(color)); + applyColorComponentToStack(stackBucket, color); coloredItems.add(Triple.of(stackWool, stackBrush, stackBucket)); } @@ -138,16 +137,13 @@ static void buildCreativeTab(final BuildCreativeModeTabContentsEvent event) { } } - private static CompoundTag getTagWithColorFromDyeColor(DyeColor color) { + private static void applyColorComponentToStack(ItemStack stack, DyeColor color) { float[] colors = color.getTextureDiffuseColors(); int r = (int) (colors[0] * 255.0F); int g = (int) (colors[1] * 255.0F); int b = (int) (colors[2] * 255.0F); - CompoundTag tag = new CompoundTag(); - tag.putInt("Color", (r << 16) + (g << 8) + b); - - return tag; + stack.set(UselessDataComponents.COLOR.get(), (r << 16) + (g << 8) + b); } /** diff --git a/src/main/java/net/themcbrothers/uselessmod/init/UselessDataComponents.java b/src/main/java/net/themcbrothers/uselessmod/init/UselessDataComponents.java new file mode 100644 index 00000000..b70d7631 --- /dev/null +++ b/src/main/java/net/themcbrothers/uselessmod/init/UselessDataComponents.java @@ -0,0 +1,44 @@ +package net.themcbrothers.uselessmod.init; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.NonNullList; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.themcbrothers.uselessmod.api.CoffeeType; + +import java.util.List; + +public final class UselessDataComponents { + static void register() { + } + + public static final DeferredHolder, DataComponentType> COLOR = Registration.DATA_COMPONENT_TYPES.register("color", + () -> DataComponentType.builder() + .persistent(ExtraCodecs.NON_NEGATIVE_INT) + .networkSynchronized(ByteBufCodecs.VAR_INT) + .build()); + public static final DeferredHolder, DataComponentType>> LIGHTS = Registration.DATA_COMPONENT_TYPES.register("lights", + () -> DataComponentType.>builder() + .persistent(BlockPos.CODEC.listOf()) + .networkSynchronized(BlockPos.STREAM_CODEC.apply(ByteBufCodecs.collection(NonNullList::createWithCapacity))) + .build()); + public static final DeferredHolder, DataComponentType> MIMIC = Registration.DATA_COMPONENT_TYPES.register("mimic", + () -> DataComponentType.builder() + .persistent(BlockState.CODEC) + .build()); + + public static final DeferredHolder, DataComponentType> COFFEE_TYPE = Registration.DATA_COMPONENT_TYPES.register("coffee_type", + () -> DataComponentType.builder() + .persistent(CoffeeType.CODEC) + .build()); + + public static final DeferredHolder, DataComponentType> WALL_CLOSET_MATERIAL = Registration.DATA_COMPONENT_TYPES.register("wall_closet_material", + () -> DataComponentType.builder() + .persistent(BuiltInRegistries.BLOCK.byNameCodec()) + .build()); +} diff --git a/src/main/java/net/themcbrothers/uselessmod/init/UselessFluidTypes.java b/src/main/java/net/themcbrothers/uselessmod/init/UselessFluidTypes.java index 5ba35f14..361b73ad 100644 --- a/src/main/java/net/themcbrothers/uselessmod/init/UselessFluidTypes.java +++ b/src/main/java/net/themcbrothers/uselessmod/init/UselessFluidTypes.java @@ -36,14 +36,14 @@ public ResourceLocation getFlowingTexture() { @Override public int getTintColor(FluidStack stack) { - return stack.hasTag() ? stack.getTag().getInt("Color") : 0xFFFFFFFF; + return stack.getOrDefault(UselessDataComponents.COLOR.get(), 0xFFFFFFFF); } }); } @Override public ItemStack getBucket(FluidStack stack) { - return new ItemStack(ModItems.BUCKET_PAINT, 1, stack.getTag()); + return new ItemStack(ModItems.BUCKET_PAINT, 1, stack.getComponentsPatch()); } }); } diff --git a/src/main/java/net/themcbrothers/uselessmod/network/MessageProxy.java b/src/main/java/net/themcbrothers/uselessmod/network/MessageProxy.java index 9479f49c..ebf8368e 100644 --- a/src/main/java/net/themcbrothers/uselessmod/network/MessageProxy.java +++ b/src/main/java/net/themcbrothers/uselessmod/network/MessageProxy.java @@ -10,7 +10,7 @@ public static Runnable receiveServerUpdates(BlockPos pos, CompoundTag nbt) { net.minecraft.client.multiplayer.ClientLevel level = net.minecraft.client.Minecraft.getInstance().level; if (level != null) { if (level.getBlockEntity(pos) instanceof SyncableBlockEntity blockEntity) { - blockEntity.receiveMessageFromServer(nbt); + blockEntity.receiveMessageFromServer(nbt, level.registryAccess()); } } }; diff --git a/src/main/java/net/themcbrothers/uselessmod/network/UselessPacketHandler.java b/src/main/java/net/themcbrothers/uselessmod/network/UselessPacketHandler.java index 424dd2a0..7be61c85 100644 --- a/src/main/java/net/themcbrothers/uselessmod/network/UselessPacketHandler.java +++ b/src/main/java/net/themcbrothers/uselessmod/network/UselessPacketHandler.java @@ -14,12 +14,12 @@ public UselessPacketHandler(IEventBus modEventBus, String modId, Version version @Override protected void registerClientToServer(PacketRegistrar registrar) { - registrar.play(CoffeeMachineStartPacket.ID, CoffeeMachineStartPacket::new); - registrar.play(CoffeeMachineMilkUpdatePacket.ID, CoffeeMachineMilkUpdatePacket::new); + registrar.play(CoffeeMachineStartPacket.TYPE, CoffeeMachineStartPacket.STREAM_CODEC); + registrar.play(CoffeeMachineMilkUpdatePacket.TYPE, CoffeeMachineMilkUpdatePacket.STREAM_CODEC); } @Override protected void registerServerToClient(PacketRegistrar registrar) { - registrar.play(BlockEntitySyncPacket.ID, BlockEntitySyncPacket::new); + registrar.play(BlockEntitySyncPacket.TYPE, BlockEntitySyncPacket.STREAM_CODEC); } } diff --git a/src/main/java/net/themcbrothers/uselessmod/network/packets/BlockEntitySyncPacket.java b/src/main/java/net/themcbrothers/uselessmod/network/packets/BlockEntitySyncPacket.java index 19e77e27..d7403d0b 100644 --- a/src/main/java/net/themcbrothers/uselessmod/network/packets/BlockEntitySyncPacket.java +++ b/src/main/java/net/themcbrothers/uselessmod/network/packets/BlockEntitySyncPacket.java @@ -3,7 +3,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.neoforged.api.distmarker.Dist; import net.neoforged.fml.LogicalSide; import net.neoforged.fml.loading.FMLEnvironment; @@ -16,25 +17,23 @@ import java.util.Objects; public record BlockEntitySyncPacket(BlockPos pos, CompoundTag tag) implements PacketMessage { - public static final ResourceLocation ID = UselessMod.rl("block_entity_sync"); - - public BlockEntitySyncPacket(SyncableBlockEntity blockEntity, CompoundTag tag) { - this(blockEntity.getSyncTile().getBlockPos(), tag); - } - - public BlockEntitySyncPacket(FriendlyByteBuf buffer) { - this(buffer.readBlockPos(), Objects.requireNonNull(buffer.readNbt())); - } + public static final Type TYPE = new Type<>(UselessMod.rl("block_entity_sync")); + public static final StreamCodec STREAM_CODEC = new StreamCodec<>() { + @Override + public BlockEntitySyncPacket decode(FriendlyByteBuf buf) { + return new BlockEntitySyncPacket(buf.readBlockPos(), Objects.requireNonNull(buf.readNbt())); + } - @Override - public ResourceLocation id() { - return ID; - } + @Override + public void encode(FriendlyByteBuf buf, BlockEntitySyncPacket packet) { + buf.writeBlockPos(packet.pos); + buf.writeNbt(packet.tag); + } + }; @Override - public void write(FriendlyByteBuf packetBuffer) { - packetBuffer.writeBlockPos(this.pos); - packetBuffer.writeNbt(this.tag); + public Type type() { + return TYPE; } @Override @@ -43,7 +42,7 @@ public void handle(PlayPayloadContext context) { context.level().ifPresent(level -> { if (level.isAreaLoaded(this.pos, 1)) { if (level.getBlockEntity(this.pos) instanceof SyncableBlockEntity blockEntity) { - blockEntity.receiveMessageFromClient(this.tag); + blockEntity.receiveMessageFromClient(this.tag, level.registryAccess()); } } }); diff --git a/src/main/java/net/themcbrothers/uselessmod/network/packets/CoffeeMachineMilkUpdatePacket.java b/src/main/java/net/themcbrothers/uselessmod/network/packets/CoffeeMachineMilkUpdatePacket.java index bd620e0d..c001cdfa 100644 --- a/src/main/java/net/themcbrothers/uselessmod/network/packets/CoffeeMachineMilkUpdatePacket.java +++ b/src/main/java/net/themcbrothers/uselessmod/network/packets/CoffeeMachineMilkUpdatePacket.java @@ -1,7 +1,8 @@ package net.themcbrothers.uselessmod.network.packets; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.neoforged.neoforge.network.handling.PlayPayloadContext; import net.themcbrothers.lib.network.PacketMessage; import net.themcbrothers.lib.network.PacketUtils; @@ -10,20 +11,22 @@ import net.themcbrothers.uselessmod.world.level.block.entity.CoffeeMachineBlockEntity; public record CoffeeMachineMilkUpdatePacket(boolean useMilk) implements PacketMessage { - public static final ResourceLocation ID = UselessMod.rl("coffee_machine_milk_update"); + public static final Type TYPE = new Type<>(UselessMod.rl("coffee_machine_milk_update")); + public static final StreamCodec STREAM_CODEC = new StreamCodec<>() { + @Override + public CoffeeMachineMilkUpdatePacket decode(FriendlyByteBuf buf) { + return new CoffeeMachineMilkUpdatePacket(buf.readBoolean()); + } - public CoffeeMachineMilkUpdatePacket(FriendlyByteBuf buffer) { - this(buffer.readBoolean()); - } - - @Override - public ResourceLocation id() { - return ID; - } + @Override + public void encode(FriendlyByteBuf buf, CoffeeMachineMilkUpdatePacket packet) { + buf.writeBoolean(packet.useMilk); + } + }; @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeBoolean(this.useMilk); + public Type type() { + return TYPE; } @Override diff --git a/src/main/java/net/themcbrothers/uselessmod/network/packets/CoffeeMachineStartPacket.java b/src/main/java/net/themcbrothers/uselessmod/network/packets/CoffeeMachineStartPacket.java index 052796c5..00c61f81 100644 --- a/src/main/java/net/themcbrothers/uselessmod/network/packets/CoffeeMachineStartPacket.java +++ b/src/main/java/net/themcbrothers/uselessmod/network/packets/CoffeeMachineStartPacket.java @@ -1,7 +1,8 @@ package net.themcbrothers.uselessmod.network.packets; import net.minecraft.network.FriendlyByteBuf; -import net.minecraft.resources.ResourceLocation; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.neoforged.neoforge.network.handling.PlayPayloadContext; import net.themcbrothers.lib.network.PacketMessage; import net.themcbrothers.lib.network.PacketUtils; @@ -10,20 +11,22 @@ import net.themcbrothers.uselessmod.world.level.block.entity.CoffeeMachineBlockEntity; public record CoffeeMachineStartPacket(boolean start) implements PacketMessage { - public static final ResourceLocation ID = UselessMod.rl("coffee_machine_start"); + public static final Type TYPE = new Type<>(UselessMod.rl("coffee_machine_start")); + public static final StreamCodec STREAM_CODEC = new StreamCodec<>() { + @Override + public CoffeeMachineStartPacket decode(FriendlyByteBuf buf) { + return new CoffeeMachineStartPacket(buf.readBoolean()); + } - public CoffeeMachineStartPacket(FriendlyByteBuf buffer) { - this(buffer.readBoolean()); - } - - @Override - public ResourceLocation id() { - return ID; - } + @Override + public void encode(FriendlyByteBuf buf, CoffeeMachineStartPacket packet) { + buf.writeBoolean(packet.start); + } + }; @Override - public void write(FriendlyByteBuf buffer) { - buffer.writeBoolean(this.start); + public Type type() { + return TYPE; } @Override diff --git a/src/main/java/net/themcbrothers/uselessmod/setup/ClientSetup.java b/src/main/java/net/themcbrothers/uselessmod/setup/ClientSetup.java index 4ff90f86..7cdcbe21 100644 --- a/src/main/java/net/themcbrothers/uselessmod/setup/ClientSetup.java +++ b/src/main/java/net/themcbrothers/uselessmod/setup/ClientSetup.java @@ -3,26 +3,18 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.color.block.BlockColors; import net.minecraft.client.color.item.ItemColors; -import net.minecraft.client.model.EntityModel; import net.minecraft.client.model.SkullModel; import net.minecraft.client.model.geom.ModelLayers; -import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.renderer.Sheets; import net.minecraft.client.renderer.blockentity.BlockEntityRenderers; import net.minecraft.client.renderer.blockentity.HangingSignRenderer; import net.minecraft.client.renderer.blockentity.SignRenderer; import net.minecraft.client.renderer.blockentity.SkullBlockRenderer; -import net.minecraft.client.renderer.entity.LivingEntityRenderer; import net.minecraft.client.renderer.entity.player.PlayerRenderer; import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.client.resources.PlayerSkin; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtUtils; -import net.minecraft.nbt.Tag; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ElytraItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.state.BlockState; @@ -131,26 +123,18 @@ private void itemColors(final RegisterColorHandlersEvent.Item event) { final ItemColors colors = event.getItemColors(); event.register(((stack, layer) -> { - final CompoundTag tag = stack.getTag(); - return layer == 1 && tag != null && tag.contains("Color", Tag.TAG_ANY_NUMERIC) ? tag.getInt("Color") : -1; + Integer color = stack.get(UselessDataComponents.COLOR.get()); + return layer == 1 && color != null ? color : -1; }), ModItems.PAINT_BRUSH); - event.register(((stack, layer) -> { - final CompoundTag tag = BlockItem.getBlockEntityData(stack); - return tag != null && tag.contains("Color", Tag.TAG_ANY_NUMERIC) ? tag.getInt("Color") : -1; - }), ModBlocks.PAINTED_WOOL); + event.register(((stack, layer) -> stack.getOrDefault(UselessDataComponents.COLOR.get(), -1)), ModBlocks.PAINTED_WOOL); event.register((stack, layer) -> CoffeeUtils.getCoffeeType(stack).map(CoffeeType::getColor).orElse(-1), ModBlocks.CUP_COFFEE); event.register((stack, layer) -> { - final CompoundTag tag = BlockItem.getBlockEntityData(stack); - final ClientLevel level = Minecraft.getInstance().level; - if (level != null && tag != null && tag.contains("Mimic", Tag.TAG_COMPOUND)) { - final BlockState mimic = NbtUtils.readBlockState(level.holderLookup(Registries.BLOCK), tag.getCompound("Mimic")); - return colors.getColor(new ItemStack(mimic.getBlock().asItem()), layer); - } - return -1; + BlockState mimic = stack.get(UselessDataComponents.MIMIC.get()); + return mimic != null ? colors.getColor(new ItemStack(mimic.getBlock().asItem()), layer) : -1; }, ModBlocks.MACHINE_SUPPLIER); event.register(new DynamicFluidContainerModel.Colors(), ModItems.BUCKET_PAINT); diff --git a/src/main/java/net/themcbrothers/uselessmod/util/CoffeeUtils.java b/src/main/java/net/themcbrothers/uselessmod/util/CoffeeUtils.java index 0430bbf6..5cb581a2 100644 --- a/src/main/java/net/themcbrothers/uselessmod/util/CoffeeUtils.java +++ b/src/main/java/net/themcbrothers/uselessmod/util/CoffeeUtils.java @@ -1,13 +1,10 @@ package net.themcbrothers.uselessmod.util; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; -import net.minecraft.resources.ResourceLocation; import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.item.ItemStack; import net.themcbrothers.uselessmod.api.CoffeeType; -import net.themcbrothers.uselessmod.api.UselessRegistries; import net.themcbrothers.uselessmod.init.ModBlocks; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import org.jetbrains.annotations.NotNull; import java.util.Collections; @@ -15,16 +12,8 @@ import java.util.Set; public class CoffeeUtils { - private static final String TAG_COFFEE = "Coffee"; - public static Optional getCoffeeType(final ItemStack stack) { - final CompoundTag tag = stack.getTag(); - if (tag != null && tag.contains(TAG_COFFEE, Tag.TAG_STRING)) { - final ResourceLocation registryName = ResourceLocation.tryParse(tag.getString(TAG_COFFEE)); - return Optional.ofNullable(UselessRegistries.COFFEE_REGISTRY.get(registryName)); - } - - return Optional.empty(); + return Optional.ofNullable(stack.get(UselessDataComponents.COFFEE_TYPE.get())); } @NotNull @@ -35,7 +24,7 @@ public static Set getMobEffects(final ItemStack stack) { @NotNull public static ItemStack createCoffeeStack(final CoffeeType type) { final ItemStack stack = new ItemStack(ModBlocks.CUP_COFFEE); - stack.getOrCreateTag().putString(TAG_COFFEE, String.valueOf(UselessRegistries.COFFEE_REGISTRY.getKey(type))); + stack.set(UselessDataComponents.COFFEE_TYPE.get(), type); return stack; } } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/item/BucketWithPaintItem.java b/src/main/java/net/themcbrothers/uselessmod/world/item/BucketWithPaintItem.java index bba39785..18efecc7 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/item/BucketWithPaintItem.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/item/BucketWithPaintItem.java @@ -1,8 +1,6 @@ package net.themcbrothers.uselessmod.world.item; import net.minecraft.ChatFormatting; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.world.item.BucketItem; import net.minecraft.world.item.ItemStack; @@ -13,6 +11,7 @@ import net.neoforged.neoforge.fluids.FluidType; import net.neoforged.neoforge.fluids.capability.wrappers.FluidBucketWrapper; import net.themcbrothers.uselessmod.UselessMod; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.init.UselessFluids; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,10 +26,9 @@ public BucketWithPaintItem(Supplier supplier, Properties builde @Override public void appendHoverText(ItemStack stack, @Nullable Level level, List hoverText, TooltipFlag tooltipFlag) { - CompoundTag tag = stack.getTag(); + Integer color = stack.get(UselessDataComponents.COLOR.get()); - if (tag != null && tag.contains("Color", Tag.TAG_ANY_NUMERIC)) { - int color = tag.getInt("Color"); + if (color != null) { String hexColor = String.format("#%06X", (0xFFFFFF & color)); hoverText.add(UselessMod.translate("misc", "color", hexColor).withStyle(ChatFormatting.GRAY)); } @@ -44,12 +42,7 @@ public PaintFluidBucketWrapper(@NotNull ItemStack container) { @Override public @NotNull FluidStack getFluid() { FluidStack fluidStack = new FluidStack(UselessFluids.PAINT.get(), FluidType.BUCKET_VOLUME); - CompoundTag tag = this.container.getTag(); - - if (tag != null && tag.contains("Color", Tag.TAG_ANY_NUMERIC)) { - fluidStack.getOrCreateTag().putInt("Color", tag.getInt("Color")); - } - + fluidStack.applyComponents(this.container.getComponents()); return fluidStack; } } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/item/CupBlockItem.java b/src/main/java/net/themcbrothers/uselessmod/world/item/CupBlockItem.java index 9f77d29b..293c6750 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/item/CupBlockItem.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/item/CupBlockItem.java @@ -48,8 +48,8 @@ public ItemStack finishUsingItem(ItemStack stack, Level level, LivingEntity enti if (!level.isClientSide) { for (MobEffectInstance mobeffectinstance : CoffeeUtils.getMobEffects(stack)) { - if (mobeffectinstance.getEffect().isInstantenous()) { - mobeffectinstance.getEffect().applyInstantenousEffect(player, player, entity, mobeffectinstance.getAmplifier(), 1.0D); + if (mobeffectinstance.getEffect().value().isInstantenous()) { + mobeffectinstance.getEffect().value().applyInstantenousEffect(player, player, entity, mobeffectinstance.getAmplifier(), 1.0D); } else { entity.addEffect(new MobEffectInstance(mobeffectinstance)); } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/item/LightSwitchBlockItem.java b/src/main/java/net/themcbrothers/uselessmod/world/item/LightSwitchBlockItem.java index c448b45e..f8441e99 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/item/LightSwitchBlockItem.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/item/LightSwitchBlockItem.java @@ -4,7 +4,6 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.InteractionHand; @@ -21,10 +20,10 @@ import net.neoforged.fml.ModList; import net.themcbrothers.uselessmod.UselessMod; import net.themcbrothers.uselessmod.api.LampRegistry; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; -import java.util.Arrays; import java.util.List; import static net.themcbrothers.uselessmod.UselessMod.translate; @@ -36,12 +35,11 @@ public LightSwitchBlockItem(Block block, Properties properties) { @Override public void appendHoverText(ItemStack stack, @Nullable Level level, List tooltip, TooltipFlag flag) { - CompoundTag tag = getBlockEntityData(stack); + List lights = stack.get(UselessDataComponents.LIGHTS.get()); - if (level != null && tag != null) { + if (level != null && lights != null) { if (GLFW.glfwGetKey(Minecraft.getInstance().getWindow().getWindow(), GLFW.GLFW_KEY_LEFT_SHIFT) == GLFW.GLFW_PRESS) { - for (long packedPos : tag.getLongArray("Lights")) { - final BlockPos pos = BlockPos.of(packedPos); + for (BlockPos pos : lights) { final BlockState state = level.getBlockState(pos); final ItemStack cloneStack = state.getCloneItemStack(Minecraft.getInstance().hitResult, level, pos, UselessMod.setup.getLocalPlayer()); final String modId = cloneStack.getItem().getCreatorModId(cloneStack); @@ -68,18 +66,20 @@ public InteractionResult useOn(UseOnContext context) { final ItemStack stack = context.getItemInHand(); if (LampRegistry.isLampRegistered(state)) { - // create or get BlockEntityTag from ItemStack - CompoundTag blockEntityTag = stack.getOrCreateTagElement("BlockEntityTag"); - List positions = Lists.newArrayList(Arrays.stream(blockEntityTag.getLongArray("Lights")).iterator()); + List existingLights = stack.get(UselessDataComponents.LIGHTS.get()); + List lights = Lists.newArrayList(); + + if (existingLights != null) { + lights.addAll(existingLights); + } - long longPos = pos.asLong(); Component statusMessage; - if (positions.contains(longPos)) { + if (lights.contains(pos)) { statusMessage = translate("status", "light_switch.block_already_added").withStyle(ChatFormatting.RED); } else { - positions.add(longPos); - blockEntityTag.putLongArray("Lights", positions); + lights.add(pos); + stack.set(UselessDataComponents.LIGHTS.get(), lights); statusMessage = translate("status", "light_switch.block_added", pos.toShortString()); } @@ -98,7 +98,7 @@ public InteractionResultHolder use(Level level, Player player, Intera final ItemStack stack = player.getItemInHand(usedHand); if (player.isSecondaryUseActive()) { - stack.setTag(null); + stack.remove(UselessDataComponents.LIGHTS.get()); player.displayClientMessage(translate("status", "light_switch.cleared"), true); return InteractionResultHolder.sidedSuccess(stack, level.isClientSide); } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/item/PaintBrushItem.java b/src/main/java/net/themcbrothers/uselessmod/world/item/PaintBrushItem.java index 82b823ae..7b680a7e 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/item/PaintBrushItem.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/item/PaintBrushItem.java @@ -2,8 +2,6 @@ import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerPlayer; import net.minecraft.tags.BlockTags; @@ -18,6 +16,7 @@ import net.minecraft.world.level.Level; import net.themcbrothers.uselessmod.UselessMod; import net.themcbrothers.uselessmod.init.ModBlocks; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.world.level.block.entity.PaintedWoolBlockEntity; import org.jetbrains.annotations.Nullable; @@ -35,10 +34,9 @@ public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantmen @Override public void appendHoverText(ItemStack stack, @Nullable Level level, List hoverText, TooltipFlag tooltipFlag) { - CompoundTag tag = stack.getTag(); + Integer color = stack.get(UselessDataComponents.COLOR.get()); - if (tag != null && tag.contains("Color", Tag.TAG_ANY_NUMERIC)) { - int color = tag.getInt("Color"); + if (color != null) { String hexColor = String.format("#%06X", (0xFFFFFF & color)); hoverText.add(UselessMod.translate("misc", "color", hexColor).withStyle(ChatFormatting.GRAY)); } @@ -62,7 +60,8 @@ public InteractionResult useOn(UseOnContext context) { level.scheduleTick(pos, paintedWool.getBlockState().getBlock(), 2); if (player == null || !player.getAbilities().instabuild) { - stack.hurt(1, level.getRandom(), player instanceof ServerPlayer ? (ServerPlayer) player : null); + stack.hurtAndBreak(1, level.getRandom(), player instanceof ServerPlayer ? (ServerPlayer) player : null, () -> { + }); } return InteractionResult.sidedSuccess(level.isClientSide); @@ -76,7 +75,7 @@ public void setDamage(ItemStack stack, int damage) { super.setDamage(stack, damage); if (damage >= this.getMaxDamage(stack)) { - stack.getOrCreateTag().remove("Color"); + stack.remove(UselessDataComponents.COLOR.get()); } } @@ -91,17 +90,15 @@ public int getBarColor(ItemStack stack) { } public boolean hasCustomColor(ItemStack stack) { - CompoundTag tag = stack.getTag(); - return tag != null && tag.contains("Color", 99); + return stack.has(UselessDataComponents.COLOR.get()); } public int getColor(ItemStack stack) { - CompoundTag tag = stack.getTag(); - return tag != null && tag.contains("Color", 99) ? tag.getInt("Color") : -1; + return stack.getOrDefault(UselessDataComponents.COLOR.get(), -1); } public void setColor(ItemStack stack, int color) { - stack.getOrCreateTag().putInt("Color", color); + stack.set(UselessDataComponents.COLOR.get(), color); } public static ItemStack dye(ItemStack stack, List dyes) { diff --git a/src/main/java/net/themcbrothers/uselessmod/world/item/crafting/CoffeeRecipe.java b/src/main/java/net/themcbrothers/uselessmod/world/item/crafting/CoffeeRecipe.java index d5737be9..f14cab0d 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/item/crafting/CoffeeRecipe.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/item/crafting/CoffeeRecipe.java @@ -4,7 +4,8 @@ import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.core.NonNullList; import net.minecraft.core.RegistryAccess; -import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.codec.StreamCodec; import net.minecraft.util.ExtraCodecs; import net.minecraft.world.Container; import net.minecraft.world.item.ItemStack; @@ -110,39 +111,44 @@ public static class Serializer implements RecipeSerializer { ExtraCodecs.strictOptionalField(Ingredient.CODEC, "extra", Ingredient.EMPTY).forGetter(recipe -> recipe.extraIngredient), FluidIngredient.CODEC_NONEMPTY.fieldOf("water").forGetter(recipe -> recipe.waterIngredient), ExtraCodecs.strictOptionalField(FluidIngredient.CODEC, "milk", FluidIngredient.EMPTY).forGetter(recipe -> recipe.milkIngredient), - ItemStack.ITEM_WITH_COUNT_CODEC.fieldOf("result").forGetter(recipe -> recipe.result), + ItemStack.SINGLE_ITEM_CODEC.fieldOf("result").forGetter(recipe -> recipe.result), Codec.INT.fieldOf("cookingtime").orElse(150).forGetter(recipe -> recipe.cookingTime) ).apply(instance, CoffeeRecipe::new)); + private static final StreamCodec STREAM_CODEC = StreamCodec.of(Serializer::toNetwork, Serializer::fromNetwork); + @Override public Codec codec() { return CODEC; } @Override - public CoffeeRecipe fromNetwork(FriendlyByteBuf buffer) { + public StreamCodec streamCodec() { + return STREAM_CODEC; + } + + private static CoffeeRecipe fromNetwork(RegistryFriendlyByteBuf buffer) { String group = buffer.readUtf(); - Ingredient cupIngredient = Ingredient.fromNetwork(buffer); - Ingredient beanIngredient = Ingredient.fromNetwork(buffer); - Ingredient extraIngredient = Ingredient.fromNetwork(buffer); - FluidIngredient waterIngredient = FluidIngredient.fromNetwork(buffer); - FluidIngredient milkIngredient = FluidIngredient.fromNetwork(buffer); - ItemStack recipeOutput = buffer.readItem(); + Ingredient cupIngredient = Ingredient.CONTENTS_STREAM_CODEC.decode(buffer); + Ingredient beanIngredient = Ingredient.CONTENTS_STREAM_CODEC.decode(buffer); + Ingredient extraIngredient = Ingredient.CONTENTS_STREAM_CODEC.decode(buffer); + FluidIngredient waterIngredient = FluidIngredient.CONTENTS_STREAM_CODEC.decode(buffer); + FluidIngredient milkIngredient = FluidIngredient.CONTENTS_STREAM_CODEC.decode(buffer); + ItemStack recipeOutput = ItemStack.STREAM_CODEC.decode(buffer); int cookingTime = buffer.readInt(); return new CoffeeRecipe(group, cupIngredient, beanIngredient, extraIngredient, waterIngredient, milkIngredient, recipeOutput, cookingTime); } - @Override - public void toNetwork(FriendlyByteBuf buffer, CoffeeRecipe recipe) { + private static void toNetwork(RegistryFriendlyByteBuf buffer, CoffeeRecipe recipe) { buffer.writeUtf(recipe.group); - recipe.cupIngredient.toNetwork(buffer); - recipe.beanIngredient.toNetwork(buffer); - recipe.extraIngredient.toNetwork(buffer); - recipe.waterIngredient.toNetwork(buffer); - recipe.milkIngredient.toNetwork(buffer); - buffer.writeItem(recipe.result); + Ingredient.CONTENTS_STREAM_CODEC.encode(buffer, recipe.cupIngredient); + Ingredient.CONTENTS_STREAM_CODEC.encode(buffer, recipe.cupIngredient); + Ingredient.CONTENTS_STREAM_CODEC.encode(buffer, recipe.cupIngredient); + FluidIngredient.CONTENTS_STREAM_CODEC.encode(buffer, recipe.waterIngredient); + FluidIngredient.CONTENTS_STREAM_CODEC.encode(buffer, recipe.milkIngredient); + ItemStack.STREAM_CODEC.encode(buffer, recipe.result); buffer.writeInt(recipe.cookingTime); } } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/item/crafting/LightSwitchConvertRecipe.java b/src/main/java/net/themcbrothers/uselessmod/world/item/crafting/LightSwitchConvertRecipe.java index 39efd998..ddd03e62 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/item/crafting/LightSwitchConvertRecipe.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/item/crafting/LightSwitchConvertRecipe.java @@ -47,7 +47,7 @@ public ItemStack assemble(CraftingContainer container, RegistryAccess registryAc } ItemStack returnStack = new ItemStack(isBlock ? ModBlocks.LIGHT_SWITCH : ModBlocks.LIGHT_SWITCH_BLOCK); - returnStack.setTag(stack.getTag()); + returnStack.applyComponents(stack.getComponents()); return returnStack; } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/CoffeeMachineBlock.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/CoffeeMachineBlock.java index efcdf1f0..5125cd73 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/CoffeeMachineBlock.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/CoffeeMachineBlock.java @@ -6,7 +6,9 @@ import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; @@ -78,11 +80,16 @@ public RenderShape getRenderShape(BlockState state) { } @Override - public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (this.tryWrench(state, level, pos, player, hand, hit)) { - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } + return super.useItemOn(stack, state, level, pos, player, hand, hit); + } + + @Override + public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult hit) { if (player instanceof ServerPlayer serverPlayer && level.getBlockEntity(pos) instanceof CoffeeMachineBlockEntity coffeeMachine) { serverPlayer.openMenu(coffeeMachine, pos); player.awardStat(ModStats.INTERACT_WITH_COFFEE_MACHINE.get()); diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/CupBlock.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/CupBlock.java index a9745f02..5eb1ed0b 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/CupBlock.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/CupBlock.java @@ -3,7 +3,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; +import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -78,8 +78,8 @@ public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable L } @Override - public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { - return this.tryWrench(state, level, pos, player, hand, hit) ? InteractionResult.sidedSuccess(level.isClientSide) : InteractionResult.PASS; + protected ItemInteractionResult useItemOn(ItemStack p_316304_, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + return this.tryWrench(state, level, pos, player, hand, hit) ? ItemInteractionResult.sidedSuccess(level.isClientSide) : ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } @Override diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/LightSwitchBlock.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/LightSwitchBlock.java index df9c5c11..7fd04e2b 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/LightSwitchBlock.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/LightSwitchBlock.java @@ -3,14 +3,8 @@ import com.mojang.serialization.MapCodec; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; -import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.BlockItem; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -30,8 +24,6 @@ import net.themcbrothers.uselessmod.world.level.block.entity.LightSwitchBlockEntity; import org.jetbrains.annotations.Nullable; -import java.util.Arrays; -import java.util.List; import java.util.Map; /** @@ -74,23 +66,13 @@ protected void createBlockStateDefinition(StateDefinition.Builder lights = Arrays.stream(tag.getLongArray("Lights")).mapToObj(BlockPos::of).toList(); - - if (level.getBlockEntity(pos) instanceof LightSwitchBlockEntity blockEntity) { - blockEntity.setBlockPositions(lights); - } - } - } } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/LightSwitchBlockBlock.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/LightSwitchBlockBlock.java index cd52717e..aedf1d16 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/LightSwitchBlockBlock.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/LightSwitchBlockBlock.java @@ -3,8 +3,6 @@ import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; @@ -60,7 +58,6 @@ public void neighborChanged(BlockState state, Level level, BlockPos pos, Block b } } - @SuppressWarnings("deprecation") @Override public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource random) { if (state.getValue(POWERED) && !level.hasNeighborSignal(pos)) { @@ -72,14 +69,6 @@ public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource } } - /** - * Called by BlockItem after this block has been placed. - */ - @Override - public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) { - LightSwitchBlock.setPlacedBy(level, pos, stack); - } - @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/MachineSupplierBlock.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/MachineSupplierBlock.java index 9abda5d4..e2b4538e 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/MachineSupplierBlock.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/MachineSupplierBlock.java @@ -6,14 +6,11 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.registries.Registries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtUtils; -import net.minecraft.nbt.Tag; +import net.minecraft.core.RegistryAccess; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; -import net.minecraft.world.InteractionResult; +import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.Mob; @@ -27,7 +24,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.FluidState; -import net.minecraft.world.level.pathfinder.BlockPathTypes; +import net.minecraft.world.level.pathfinder.PathType; import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.VoxelShape; @@ -36,6 +33,7 @@ import net.themcbrothers.lib.wrench.WrenchUtils; import net.themcbrothers.lib.wrench.WrenchableBlock; import net.themcbrothers.uselessmod.init.ModBlockEntityTypes; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.world.level.block.entity.MachineSupplierBlockEntity; import org.jetbrains.annotations.Nullable; @@ -45,6 +43,7 @@ @SuppressWarnings("deprecation") public class MachineSupplierBlock extends BaseEntityBlock implements WrenchableBlock { public static final MapCodec CODEC = simpleCodec(MachineSupplierBlock::new); + public MachineSupplierBlock(Properties properties) { super(properties); } @@ -66,24 +65,22 @@ public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { } @Override - public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List hoverText, TooltipFlag tooltipFlag) { - CompoundTag tag = BlockItem.getBlockEntityData(stack); + public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List hoverText, TooltipFlag tooltipFlag, @Nullable RegistryAccess registryAccess) { + BlockState mimic = stack.get(UselessDataComponents.MIMIC.get()); ClientLevel clientLevel = Minecraft.getInstance().level; - if (clientLevel != null && tag != null && tag.contains("Mimic", Tag.TAG_COMPOUND)) { - BlockState mimic = NbtUtils.readBlockState(clientLevel.holderLookup(Registries.BLOCK), tag.getCompound("Mimic")); + if (mimic != null && clientLevel != null) { hoverText.add(mimic.getBlock().getName().withStyle(ChatFormatting.GRAY)); } } @Override - public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + protected ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { if (this.tryWrench(state, level, pos, player, hand, hit)) { - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } if (level.getBlockEntity(pos) instanceof MachineSupplierBlockEntity blockEntity) { - ItemStack stack = player.getItemInHand(hand); if (blockEntity.getMimic() == null && stack.getItem() instanceof BlockItem blockItem) { BlockState mimic = blockItem.getBlock().getStateForPlacement(new BlockPlaceContext(level, player, hand, stack, hit)); if (mimic != null && !mimic.hasBlockEntity()) { @@ -93,12 +90,12 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player stack.shrink(1); } - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } } } - return InteractionResult.PASS; + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } @Override @@ -126,15 +123,6 @@ public boolean tryWrench(BlockState state, Level level, BlockPos pos, Player pla return false; } - @Override - public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack) { - CompoundTag tag = BlockItem.getBlockEntityData(stack); - if (tag != null && tag.contains("Mimic", Tag.TAG_COMPOUND) && - level.getBlockEntity(pos) instanceof MachineSupplierBlockEntity blockEntity) { - blockEntity.setMimic(NbtUtils.readBlockState(level.holderLookup(Registries.BLOCK), tag.getCompound("Mimic"))); - } - } - @Override public BlockState updateShape(BlockState state, Direction direction, BlockState state1, LevelAccessor level, BlockPos pos, BlockPos pos1) { if (level.getBlockEntity(pos) instanceof MachineSupplierBlockEntity blockEntity) { @@ -269,7 +257,7 @@ public boolean addLandingEffects(BlockState state1, ServerLevel level, BlockPos } @Override - public @Nullable BlockPathTypes getBlockPathType(BlockState state, BlockGetter level, BlockPos pos, @Nullable Mob mob) { + public @Nullable PathType getBlockPathType(BlockState state, BlockGetter level, BlockPos pos, @Nullable Mob mob) { return this.getMimic(level, pos).getBlockPathType(level, pos, mob); } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/PaintBucketBlock.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/PaintBucketBlock.java index 151e68af..ef1296c4 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/PaintBucketBlock.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/PaintBucketBlock.java @@ -8,6 +8,7 @@ import net.minecraft.world.Containers; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; +import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; @@ -41,6 +42,7 @@ import net.themcbrothers.lib.wrench.WrenchableBlock; import net.themcbrothers.uselessmod.init.ModBlockEntityTypes; import net.themcbrothers.uselessmod.init.ModItems; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.world.level.block.entity.PaintBucketBlockEntity; import org.jetbrains.annotations.Nullable; @@ -91,10 +93,10 @@ public BlockState updateShape(BlockState state, Direction facing, BlockState new } @Override - public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { + protected ItemInteractionResult useItemOn(ItemStack p_316304_, BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) { // Interaction with Wrench if (this.tryWrench(state, level, pos, player, hand, hit)) { - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } if (level.getBlockEntity(pos) instanceof PaintBucketBlockEntity blockEntity) { @@ -103,7 +105,7 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player // Interaction with Dye Item if (DyeColor.getColor(stack) != null) { player.setItemInHand(hand, ItemHandlerHelper.insertItem(blockEntity.stackHandler, stack, false)); - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } // Interaction with bucket or fluid container @@ -111,10 +113,10 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player if (fluidHandler.isPresent()) { // TODO: invalidate if (FluidUtil.interactWithFluidHandler(player, hand, level, pos, null)) { - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } - return InteractionResult.FAIL; + return ItemInteractionResult.FAIL; } // Interaction with Stick @@ -125,7 +127,7 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player if (color != null) { blockEntity.setColor(color.getTextureDiffuseColors()); blockEntity.stackHandler.setStackInSlot(0, ItemStack.EMPTY); - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } } } @@ -134,26 +136,26 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player // Interaction with Paint Brush if (stack.is(ModItems.PAINT_BRUSH.get()) && !stack.isDamaged()) { int bucketColor = blockEntity.getColor(); - int brushColor = stack.getOrCreateTag().getInt("Color"); + int brushColor = stack.getOrDefault(UselessDataComponents.COLOR.get(), -1); if (bucketColor != brushColor || stack.isDamaged()) { - stack.getOrCreateTag().putInt("Color", bucketColor); + stack.set(UselessDataComponents.COLOR.get(), bucketColor); stack.setDamageValue(0); blockEntity.colorTank.drain(100, IFluidHandler.FluidAction.EXECUTE); - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } } else if (stack.is(Items.BRUSH)) { ItemStack newStack = new ItemStack(ModItems.PAINT_BRUSH.value()); - newStack.getOrCreateTag().putInt("Color", blockEntity.getColor()); + int brushColor = newStack.getOrDefault(UselessDataComponents.COLOR.get(), -1); newStack.setDamageValue(0); player.setItemInHand(hand, newStack); blockEntity.colorTank.drain(100, IFluidHandler.FluidAction.EXECUTE); - return InteractionResult.sidedSuccess(level.isClientSide); + return ItemInteractionResult.sidedSuccess(level.isClientSide); } } } - return InteractionResult.PASS; + return ItemInteractionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION; } @Override @@ -176,7 +178,7 @@ public VoxelShape getInteractionShape(BlockState pState, BlockGetter pLevel, Blo } @Override - public boolean isPathfindable(BlockState state, BlockGetter world, BlockPos pos, PathComputationType pathComputationType) { + protected boolean isPathfindable(BlockState state, PathComputationType pathComputationType) { return false; } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/PaintedWoolBlock.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/PaintedWoolBlock.java index 5afa90d6..86854e80 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/PaintedWoolBlock.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/PaintedWoolBlock.java @@ -3,18 +3,15 @@ import com.mojang.serialization.MapCodec; import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; +import net.minecraft.core.RegistryAccess; import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.RandomSource; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.level.BlockGetter; -import net.minecraft.world.level.Level; import net.minecraft.world.level.LevelReader; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.Block; @@ -26,6 +23,7 @@ import net.minecraft.world.phys.HitResult; import net.themcbrothers.uselessmod.UselessMod; import net.themcbrothers.uselessmod.init.ModBlockEntityTypes; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.world.level.block.entity.PaintedWoolBlockEntity; import org.jetbrains.annotations.Nullable; @@ -61,31 +59,22 @@ public void tick(BlockState state, ServerLevel level, BlockPos pos, RandomSource } } - @Override - public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity livingEntity, ItemStack stack) { - level.getBlockEntity(pos, ModBlockEntityTypes.PAINTED_WOOL.get()).ifPresent(paintedWool -> { - CompoundTag tag = BlockItem.getBlockEntityData(stack); - if (tag != null && tag.contains("Color", Tag.TAG_ANY_NUMERIC)) { - paintedWool.setColor(tag.getInt("Color")); - } - }); - } - @Override public ItemStack getCloneItemStack(BlockState state, HitResult target, LevelReader level, BlockPos pos, Player player) { final ItemStack stack = super.getCloneItemStack(state, target, level, pos, player); if (level.getBlockEntity(pos) instanceof PaintedWoolBlockEntity paintedWool) { - BlockItem.setBlockEntityData(stack, paintedWool.getType(), paintedWool.getUpdateTag()); + stack.applyComponents(paintedWool.collectComponents()); } + return stack; } @Override - public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List tooltip, TooltipFlag tooltipFlag) { - CompoundTag tag = BlockItem.getBlockEntityData(stack); - if (tag != null) { - int color = tag.getInt("Color"); + public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List tooltip, TooltipFlag tooltipFlag, @Nullable RegistryAccess registryAccess) { + Integer color = stack.get(UselessDataComponents.COLOR.get()); + + if (color != null) { String hexColor = String.format("#%06X", (0xFFFFFF & color)); tooltip.add(UselessMod.translate("misc", "color", hexColor).withStyle(ChatFormatting.GRAY)); } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/WallClosetBlock.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/WallClosetBlock.java index 5d65cb73..7ed166d1 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/WallClosetBlock.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/WallClosetBlock.java @@ -4,23 +4,17 @@ import net.minecraft.ChatFormatting; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; -import net.minecraft.core.registries.BuiltInRegistries; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.Tag; +import net.minecraft.core.RegistryAccess; import net.minecraft.network.chat.Component; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.RandomSource; import net.minecraft.world.Container; import net.minecraft.world.Containers; -import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.monster.piglin.PiglinAi; import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.context.BlockPlaceContext; @@ -40,6 +34,7 @@ import net.minecraft.world.phys.shapes.VoxelShape; import net.themcbrothers.uselessmod.init.ModBlockEntityTypes; import net.themcbrothers.uselessmod.init.ModStats; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.world.level.block.entity.WallClosetBlockEntity; import org.jetbrains.annotations.Nullable; @@ -69,12 +64,11 @@ protected MapCodec codec() { } @Override - public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List hoverText, TooltipFlag tooltipFlag) { - CompoundTag tag = BlockItem.getBlockEntityData(stack); - if (tag != null && tag.contains("Material", Tag.TAG_STRING)) { - final ResourceLocation key = ResourceLocation.tryParse(tag.getString("Material")); - Block block = BuiltInRegistries.BLOCK.get(key); - hoverText.add(block.getName().withStyle(ChatFormatting.GRAY)); + public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List hoverText, TooltipFlag tooltipFlag, @Nullable RegistryAccess registryAccess) { + Block material = stack.get(UselessDataComponents.WALL_CLOSET_MATERIAL.get()); + + if (material != null) { + hoverText.add(material.getName().withStyle(ChatFormatting.GRAY)); } } @@ -82,11 +76,7 @@ public void appendHoverText(ItemStack stack, @Nullable BlockGetter level, List getItems() { + return this.items; + } + + @Override + protected void setItems(NonNullList stacks) { + this.items.clear(); + this.items.addAll(stacks); + this.setChanged(); + } + @Override protected AbstractContainerMenu createMenu(int id, Inventory inventory) { return new CoffeeMachineMenu(id, inventory, this, this.dataAccess); } + @Override + public void applyComponents(DataComponentMap components) { + super.applyComponents(components); // TODO components + } + + @Override + public void collectComponents(DataComponentMap.Builder builder) { + super.collectComponents(builder); + } + public class CoffeeMachineTank implements IFluidHandler { final FluidTank waterTank = new FluidTank(ServerConfig.COFFEE_MACHINE_WATER_CAPACITY.get()) { @Override diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/CupBlockEntity.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/CupBlockEntity.java index cd9a31a2..986d404f 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/CupBlockEntity.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/CupBlockEntity.java @@ -2,6 +2,8 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Holder; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.network.protocol.Packet; @@ -15,6 +17,7 @@ import net.themcbrothers.uselessmod.api.CoffeeType; import net.themcbrothers.uselessmod.api.UselessRegistries; import net.themcbrothers.uselessmod.init.ModBlockEntityTypes; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import org.jetbrains.annotations.Nullable; import java.util.Objects; @@ -54,8 +57,8 @@ private void writeCoffeeNbt(CompoundTag tag) { } @Override - public void load(CompoundTag tag) { - super.load(tag); + public void load(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.load(tag, lookupProvider); if (tag.contains(TAG_COFFEE, Tag.TAG_STRING)) { var key = ResourceKey.create(UselessRegistries.COFFEE_KEY, Objects.requireNonNull(ResourceLocation.tryParse(tag.getString(TAG_COFFEE)))); this.type = UselessRegistries.COFFEE_REGISTRY.getHolder(key).orElse(null); @@ -63,14 +66,14 @@ public void load(CompoundTag tag) { } @Override - protected void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); + protected void saveAdditional(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.saveAdditional(tag, lookupProvider); this.writeCoffeeNbt(tag); } @Override - public CompoundTag getUpdateTag() { - CompoundTag tag = super.getUpdateTag(); + public CompoundTag getUpdateTag(HolderLookup.Provider lookupProvider) { + CompoundTag tag = super.getUpdateTag(lookupProvider); this.writeCoffeeNbt(tag); return tag; } @@ -80,4 +83,26 @@ public CompoundTag getUpdateTag() { public Packet getUpdatePacket() { return ClientboundBlockEntityDataPacket.create(this); } + + @Override + public void applyComponents(DataComponentMap components) { + CoffeeType type = components.get(UselessDataComponents.COFFEE_TYPE.get()); + + if (type != null) { + this.type = UselessRegistries.COFFEE_REGISTRY.wrapAsHolder(type); + } + } + + @Override + public void collectComponents(DataComponentMap.Builder builder) { + if (this.type != null) { + builder.set(UselessDataComponents.COFFEE_TYPE.get(), this.type.value()); + } + } + + @SuppressWarnings("deprecation") + @Override + public void removeComponentsFromTag(CompoundTag tag) { + tag.remove("Coffee"); + } } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/LightSwitchBlockEntity.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/LightSwitchBlockEntity.java index 98f15981..dc478b4f 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/LightSwitchBlockEntity.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/LightSwitchBlockEntity.java @@ -2,6 +2,8 @@ import com.google.common.collect.Lists; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvents; @@ -13,6 +15,7 @@ import net.minecraft.world.level.block.state.BlockState; import net.themcbrothers.uselessmod.api.LampRegistry; import net.themcbrothers.uselessmod.init.ModBlockEntityTypes; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.world.level.block.LightSwitchBlock; import java.util.Arrays; @@ -27,18 +30,28 @@ public LightSwitchBlockEntity(BlockPos pos, BlockState state) { } @Override - protected void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); + public void collectComponents(DataComponentMap.Builder builder) { + builder.set(UselessDataComponents.LIGHTS.get(), this.getBlockPositions()); + } + + @Override + public void applyComponents(DataComponentMap components) { + this.setBlockPositions(components.getOrDefault(UselessDataComponents.LIGHTS.get(), List.of())); + } - if (this.blockPositions.size() > 0) { + @Override + protected void saveAdditional(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.saveAdditional(tag, lookupProvider); + + if (!this.blockPositions.isEmpty()) { List packedPositions = this.blockPositions.stream().map(BlockPos::asLong).toList(); tag.putLongArray("Lights", packedPositions); } } @Override - public void load(CompoundTag tag) { - super.load(tag); + public void load(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.load(tag, lookupProvider); this.blockPositions.clear(); Arrays.stream(tag.getLongArray("Lights")).mapToObj(BlockPos::of).forEach(this.blockPositions::add); @@ -86,6 +99,10 @@ private void playSound(LevelAccessor worldIn, BlockPos pos, SoundEvent sound, bo worldIn.playSound(null, pos, sound, SoundSource.BLOCKS, 0.3F, isOn ? 0.6F : 0.5F); } + public List getBlockPositions() { + return this.blockPositions; + } + public void setBlockPositions(Collection blockPositions) { this.blockPositions.clear(); this.blockPositions.addAll(blockPositions); diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/MachineSupplierBlockEntity.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/MachineSupplierBlockEntity.java index 268616e3..29b81c37 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/MachineSupplierBlockEntity.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/MachineSupplierBlockEntity.java @@ -1,6 +1,7 @@ package net.themcbrothers.uselessmod.world.level.block.entity; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; @@ -44,8 +45,8 @@ public void setMimic(@Nullable BlockState mimic) { } @Override - protected void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); + protected void saveAdditional(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.saveAdditional(tag, lookupProvider); this.writeMimic(tag); } @@ -56,15 +57,15 @@ private void writeMimic(CompoundTag tag) { } @Override - public void load(CompoundTag tag) { - super.load(tag); + public void load(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.load(tag, lookupProvider); if (tag.contains("Mimic", Tag.TAG_COMPOUND) && this.level != null) { this.mimic = NbtUtils.readBlockState(this.level.holderLookup(Registries.BLOCK), tag.getCompound("Mimic")); } } @Override - public CompoundTag getUpdateTag() { + public CompoundTag getUpdateTag(HolderLookup.Provider lookupProvider) { CompoundTag tag = new CompoundTag(); this.writeMimic(tag); return tag; @@ -76,9 +77,9 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() { } @Override - public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { + public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt, HolderLookup.Provider lookupProvider) { BlockState oldMimic = this.mimic; - super.onDataPacket(net, pkt); + super.onDataPacket(net, pkt, lookupProvider); if (!Objects.equals(oldMimic, this.mimic)) { this.requestModelDataUpdate(); if (this.level != null) { diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/PaintBucketBlockEntity.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/PaintBucketBlockEntity.java index 071be95a..e9ec7e59 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/PaintBucketBlockEntity.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/PaintBucketBlockEntity.java @@ -1,18 +1,22 @@ package net.themcbrothers.uselessmod.world.level.block.entity; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket; import net.minecraft.tags.FluidTags; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; +import net.neoforged.neoforge.common.NeoForgeMod; import net.neoforged.neoforge.fluids.FluidStack; import net.neoforged.neoforge.fluids.FluidType; import net.neoforged.neoforge.fluids.capability.templates.FluidTank; import net.neoforged.neoforge.items.ItemStackHandler; import net.themcbrothers.uselessmod.UselessTags; import net.themcbrothers.uselessmod.init.ModBlockEntityTypes; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.init.UselessFluids; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,12 +40,11 @@ public PaintBucketBlockEntity(BlockPos pos, BlockState state) { } public boolean hasColor() { - return !this.colorTank.isEmpty() && this.colorTank.getFluid().getFluid().is(UselessTags.Fluids.PAINT) && this.colorTank.getFluid().hasTag(); + return !this.colorTank.isEmpty() && this.colorTank.getFluid().getFluid().is(UselessTags.Fluids.PAINT) && this.colorTank.getFluid().has(UselessDataComponents.COLOR.get()); } public int getColor() { - CompoundTag tag = this.colorTank.getFluid().getTag(); - return tag != null ? tag.getInt("Color") : -1; + return this.colorTank.getFluid().getOrDefault(UselessDataComponents.COLOR.get(), -1); } public void setColor(float[] colorValues) { @@ -49,20 +52,27 @@ public void setColor(float[] colorValues) { int g = (int) (colorValues[1] * 255.0F) << 8; int b = (int) (colorValues[2] * 255.0F); + this.setColor(r + g + b); + } + + /** + * @param color + */ + public void setColor(int color) { this.colorTank.setFluid(new FluidStack(UselessFluids.PAINT.get(), FluidType.BUCKET_VOLUME)); - this.colorTank.getFluid().getOrCreateTag().putInt("Color", r + g + b); + this.colorTank.getFluid().set(UselessDataComponents.COLOR.get(), color); this.setChanged(); } - private void saveColorAndItem(CompoundTag tag) { - tag.put("Tank", this.colorTank.writeToNBT(new CompoundTag())); - tag.put("Slots", this.stackHandler.serializeNBT()); + private void saveColorAndItem(CompoundTag tag, HolderLookup.Provider lookupProvider) { + tag.put("Tank", this.colorTank.writeToNBT(lookupProvider, new CompoundTag())); + tag.put("Slots", this.stackHandler.serializeNBT(lookupProvider)); } @Override - public CompoundTag getUpdateTag() { - CompoundTag tag = super.getUpdateTag(); - this.saveColorAndItem(tag); + public CompoundTag getUpdateTag(HolderLookup.Provider lookupProvider) { + CompoundTag tag = super.getUpdateTag(lookupProvider); + this.saveColorAndItem(tag, lookupProvider); return tag; } @@ -73,15 +83,25 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() { } @Override - protected void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); - this.saveColorAndItem(tag); + protected void saveAdditional(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.saveAdditional(tag, lookupProvider); + this.saveColorAndItem(tag, lookupProvider); + } + + @Override + public void load(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.load(tag, lookupProvider); + this.colorTank.readFromNBT(lookupProvider, tag.getCompound("Tank")); + this.stackHandler.deserializeNBT(lookupProvider, tag.getCompound("Slots")); + } + + @Override + public void collectComponents(DataComponentMap.Builder builder) { + builder.set(NeoForgeMod.FLUID_STACK_COMPONENT.get(), this.colorTank.getFluid().immutable()); } @Override - public void load(CompoundTag tag) { - super.load(tag); - this.colorTank.readFromNBT(tag.getCompound("Tank")); - this.stackHandler.deserializeNBT(tag.getCompound("Slots")); + public void applyComponents(DataComponentMap components) { + this.colorTank.setFluid(FluidStack.of(components.getOrDefault(NeoForgeMod.FLUID_STACK_COMPONENT.get(), FluidStack.EMPTY.immutable()))); } } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/PaintedWoolBlockEntity.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/PaintedWoolBlockEntity.java index 196b3b6e..fec910d0 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/PaintedWoolBlockEntity.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/PaintedWoolBlockEntity.java @@ -1,6 +1,8 @@ package net.themcbrothers.uselessmod.world.level.block.entity; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.protocol.Packet; import net.minecraft.network.protocol.game.ClientGamePacketListener; @@ -8,6 +10,7 @@ import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.themcbrothers.uselessmod.init.ModBlockEntityTypes; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import net.themcbrothers.uselessmod.world.level.block.PaintedWoolBlock; import org.jetbrains.annotations.Nullable; @@ -19,8 +22,8 @@ public PaintedWoolBlockEntity(BlockPos pos, BlockState state) { } @Override - public CompoundTag getUpdateTag() { - CompoundTag tag = super.getUpdateTag(); + public CompoundTag getUpdateTag(HolderLookup.Provider lookupProvider) { + CompoundTag tag = super.getUpdateTag(lookupProvider); tag.putInt("Color", this.color); return tag; } @@ -32,14 +35,14 @@ public Packet getUpdatePacket() { } @Override - public void load(CompoundTag tag) { - super.load(tag); + public void load(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.load(tag, lookupProvider); this.color = tag.getInt("Color"); } @Override - protected void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); + protected void saveAdditional(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.saveAdditional(tag, lookupProvider); tag.putInt("Color", this.color); } @@ -54,4 +57,20 @@ public void setColor(int color) { this.requestModelDataUpdate(); this.setChanged(); } + + @Override + public void applyComponents(DataComponentMap components) { + this.color = components.getOrDefault(UselessDataComponents.COLOR.get(), 0xFFFFFFFF); + } + + @Override + public void collectComponents(DataComponentMap.Builder builder) { + builder.set(UselessDataComponents.COLOR.get(), this.color); + } + + @SuppressWarnings("deprecation") + @Override + public void removeComponentsFromTag(CompoundTag tag) { + tag.remove("Color"); + } } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/SyncableBlockEntity.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/SyncableBlockEntity.java index da9b05ee..fb811169 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/SyncableBlockEntity.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/SyncableBlockEntity.java @@ -1,5 +1,6 @@ package net.themcbrothers.uselessmod.world.level.block.entity; +import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.level.block.entity.BlockEntity; @@ -11,9 +12,9 @@ default BlockEntity getSyncTile() { default void sendSyncPacket(int type) { } - default void receiveMessageFromServer(CompoundTag tag) { + default void receiveMessageFromServer(CompoundTag tag, HolderLookup.Provider lookupProvider) { } - default void receiveMessageFromClient(CompoundTag tag) { + default void receiveMessageFromClient(CompoundTag tag, HolderLookup.Provider lookupProvider) { } } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/WallClosetBlockEntity.java b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/WallClosetBlockEntity.java index 4e20c54f..2c54b827 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/WallClosetBlockEntity.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/level/block/entity/WallClosetBlockEntity.java @@ -1,7 +1,9 @@ package net.themcbrothers.uselessmod.world.level.block.entity; import net.minecraft.core.BlockPos; +import net.minecraft.core.HolderLookup; import net.minecraft.core.NonNullList; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -29,6 +31,7 @@ import net.neoforged.neoforge.client.model.data.ModelProperty; import net.themcbrothers.uselessmod.UselessMod; import net.themcbrothers.uselessmod.init.ModBlockEntityTypes; +import net.themcbrothers.uselessmod.init.UselessDataComponents; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -78,8 +81,8 @@ public ModelData getModelData() { } @Override - public CompoundTag getUpdateTag() { - return this.saveWithoutMetadata(); + public CompoundTag getUpdateTag(HolderLookup.Provider lookupProvider) { + return this.saveWithoutMetadata(lookupProvider); } @Nullable @@ -89,17 +92,17 @@ public ClientboundBlockEntityDataPacket getUpdatePacket() { } @Override - protected void saveAdditional(CompoundTag tag) { - super.saveAdditional(tag); - ContainerHelper.saveAllItems(tag, this.items); + protected void saveAdditional(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.saveAdditional(tag, lookupProvider); + ContainerHelper.saveAllItems(tag, this.items, lookupProvider); tag.putString("Material", String.valueOf(BuiltInRegistries.BLOCK.getKey(this.material))); } @Override - public void load(CompoundTag tag) { - super.load(tag); + public void load(CompoundTag tag, HolderLookup.Provider lookupProvider) { + super.load(tag, lookupProvider); this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); - ContainerHelper.loadAllItems(tag, this.items); + ContainerHelper.loadAllItems(tag, this.items, lookupProvider); final ResourceLocation key = ResourceLocation.tryParse(tag.getString("Material")); if (key != null) { material = BuiltInRegistries.BLOCK.containsKey(key) ? Objects.requireNonNull(BuiltInRegistries.BLOCK.get(key)) : Blocks.AIR; @@ -116,7 +119,7 @@ public void parseMaterial(String registryName) { public void setMaterial(Block material) { this.material = material; //noinspection DataFlowIssue - this.level.setBlockAndUpdate(getBlockPos(), getBlockState()); + this.getLevel().setBlockAndUpdate(this.getBlockPos(), this.getBlockState()); this.requestModelDataUpdate(); this.setChanged(); } @@ -124,6 +127,7 @@ public void setMaterial(Block material) { @Override public void startOpen(Player player) { if (!this.remove && !player.isSpectator()) { + //noinspection DataFlowIssue this.openersCounter.incrementOpeners(player, this.getLevel(), this.getBlockPos(), this.getBlockState()); } } @@ -131,12 +135,14 @@ public void startOpen(Player player) { @Override public void stopOpen(Player player) { if (!this.remove && !player.isSpectator()) { + //noinspection DataFlowIssue this.openersCounter.decrementOpeners(player, this.getLevel(), this.getBlockPos(), this.getBlockState()); } } public void recheckOpen() { if (!this.remove) { + //noinspection DataFlowIssue this.openersCounter.recheckOpeners(this.getLevel(), this.getBlockPos(), this.getBlockState()); } } @@ -146,6 +152,16 @@ protected Component getDefaultName() { return UselessMod.translate("container", "wall_closet"); } + @Override + protected NonNullList getItems() { + return this.items; + } + + @Override + protected void setItems(NonNullList items) { + this.items = items; + } + @Override protected AbstractContainerMenu createMenu(int id, Inventory inventory) { return new ChestMenu(MenuType.GENERIC_9x2, id, inventory, this, 2); @@ -206,17 +222,37 @@ public void clearContent() { } private void updateBlockState(BlockState state, boolean isOpen) { - this.level.setBlock(this.getBlockPos(), state.setValue(BlockStateProperties.OPEN, isOpen), 3); + //noinspection DataFlowIssue + this.getLevel().setBlock(this.getBlockPos(), state.setValue(BlockStateProperties.OPEN, isOpen), 3); } private void playSound(SoundEvent soundEvent) { double x = (double) this.worldPosition.getX() + 0.5D; double y = (double) this.worldPosition.getY() + 0.5D; double z = (double) this.worldPosition.getZ() + 0.5D; - this.level.playSound(null, x, y, z, soundEvent, SoundSource.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F); + //noinspection DataFlowIssue + this.getLevel().playSound(null, x, y, z, soundEvent, SoundSource.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F); } public Block getMaterial() { return this.material; } + + @Override + public void applyComponents(DataComponentMap components) { + super.applyComponents(components); + this.setMaterial(components.getOrDefault(UselessDataComponents.WALL_CLOSET_MATERIAL.get(), Blocks.AIR)); + } + + @Override + public void collectComponents(DataComponentMap.Builder builder) { + super.collectComponents(builder); + builder.set(UselessDataComponents.WALL_CLOSET_MATERIAL.get(), this.getMaterial()); + } + + @Override + public void removeComponentsFromTag(CompoundTag tag) { + super.removeComponentsFromTag(tag); + tag.remove("Material"); + } } diff --git a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessOreFeatures.java b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessOreFeatures.java index 8ecb1fdd..6d146561 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessOreFeatures.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessOreFeatures.java @@ -1,6 +1,6 @@ package net.themcbrothers.uselessmod.world.worldgen; -import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.data.worldgen.features.FeatureUtils; import net.minecraft.resources.ResourceKey; import net.minecraft.tags.BlockTags; @@ -21,7 +21,7 @@ public final class UselessOreFeatures { public static final ResourceKey> ORE_USELESS = FeatureUtils.createKey(UselessMod.MOD_ID + ":ore_useless"); public static final ResourceKey> ORE_SUPER_USELESS = FeatureUtils.createKey(UselessMod.MOD_ID + ":ore_super_useless"); - public static void bootstrap(BootstapContext> context) { + public static void bootstrap(BootstrapContext> context) { RuleTest ruleTestStone = new TagMatchTest(BlockTags.STONE_ORE_REPLACEABLES); RuleTest ruleTestDeepslate = new TagMatchTest(BlockTags.DEEPSLATE_ORE_REPLACEABLES); RuleTest ruleTestNetherrack = new BlockMatchTest(Blocks.NETHERRACK); diff --git a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessOrePlacements.java b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessOrePlacements.java index 0da586cb..23e44523 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessOrePlacements.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessOrePlacements.java @@ -2,7 +2,7 @@ import net.minecraft.core.HolderGetter; import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.levelgen.VerticalAnchor; @@ -20,7 +20,7 @@ public final class UselessOrePlacements { public static final ResourceKey ORE_SUPER_USELESS_NETHER = PlacementUtils.createKey(UselessMod.MOD_ID + ":ore_super_useless_nether"); public static final ResourceKey ORE_SUPER_USELESS_END = PlacementUtils.createKey(UselessMod.MOD_ID + ":ore_super_useless_end"); - public static void bootstrap(BootstapContext context) { + public static void bootstrap(BootstrapContext context) { HolderGetter> configuredFeatures = context.lookup(Registries.CONFIGURED_FEATURE); PlacementUtils.register(context, ORE_USELESS_MIDDLE, configuredFeatures.getOrThrow(UselessOreFeatures.ORE_USELESS), commonOrePlacement(10, HeightRangePlacement.triangle(VerticalAnchor.absolute(-24), VerticalAnchor.absolute(56)))); PlacementUtils.register(context, ORE_USELESS_NETHER, configuredFeatures.getOrThrow(UselessOreFeatures.ORE_USELESS), commonOrePlacement(5, PlacementUtils.RANGE_10_10)); diff --git a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessTreeFeatures.java b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessTreeFeatures.java index b993384e..60ad04fd 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessTreeFeatures.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessTreeFeatures.java @@ -1,6 +1,6 @@ package net.themcbrothers.uselessmod.world.worldgen; -import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.data.worldgen.features.FeatureUtils; import net.minecraft.resources.ResourceKey; import net.minecraft.util.valueproviders.ConstantInt; @@ -39,7 +39,7 @@ private static TreeConfiguration.TreeConfigurationBuilder createFancyUselessOak( return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(ModBlocks.USELESS_OAK_LOG.get()), new FancyTrunkPlacer(3, 11, 0), BlockStateProvider.simple(ModBlocks.USELESS_OAK_LEAVES.get()), new FancyFoliagePlacer(ConstantInt.of(2), ConstantInt.of(4), 4), new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4))).ignoreVines(); } - public static void bootstrap(BootstapContext> context) { + public static void bootstrap(BootstrapContext> context) { final BeehiveDecorator beehive0002 = new BeehiveDecorator(0.002F); final BeehiveDecorator beehive002 = new BeehiveDecorator(0.02F); final BeehiveDecorator beehive005 = new BeehiveDecorator(0.05F); diff --git a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessTreePlacements.java b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessTreePlacements.java index af2d1353..496c94f2 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessTreePlacements.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessTreePlacements.java @@ -2,7 +2,7 @@ import net.minecraft.core.HolderGetter; import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; @@ -17,7 +17,7 @@ public final class UselessTreePlacements { public static final ResourceKey FANCY_USELESS_OAK_BEES_002 = PlacementUtils.createKey(UselessMod.MOD_ID + ":fancy_useless_oak_bees_002"); public static final ResourceKey FANCY_USELESS_OAK_BEES = PlacementUtils.createKey(UselessMod.MOD_ID + ":fancy_useless_oak_bees"); - public static void bootstrap(BootstapContext context) { + public static void bootstrap(BootstrapContext context) { HolderGetter> configuredFeatures = context.lookup(Registries.CONFIGURED_FEATURE); PlacementUtils.register(context, USELESS_OAK_BEES_0002, configuredFeatures.getOrThrow(UselessTreeFeatures.USELESS_OAK_BEES_0002), PlacementUtils.filteredByBlockSurvival(ModBlocks.USELESS_OAK_SAPLING.get())); diff --git a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessVegetationFeatures.java b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessVegetationFeatures.java index b594e282..fa63a734 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessVegetationFeatures.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessVegetationFeatures.java @@ -2,7 +2,7 @@ import net.minecraft.core.HolderGetter; import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.data.worldgen.features.FeatureUtils; import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.resources.ResourceKey; @@ -30,7 +30,7 @@ private static RandomPatchConfiguration grassPatch(BlockStateProvider toPlace, i return FeatureUtils.simpleRandomPatchConfiguration(tries, PlacementUtils.onlyWhenEmpty(Feature.SIMPLE_BLOCK, new SimpleBlockConfiguration(toPlace))); } - public static void bootstrap(BootstapContext> context) { + public static void bootstrap(BootstrapContext> context) { HolderGetter placedFeatures = context.lookup(Registries.PLACED_FEATURE); FeatureUtils.register(context, USELESS_FLOWER_DEFAULT, Feature.FLOWER, grassPatch(new WeightedStateProvider(SimpleWeightedRandomList.builder().add(ModBlocks.RED_ROSE.get().defaultBlockState(), 2).add(ModBlocks.BLUE_ROSE.get().defaultBlockState(), 2).add(ModBlocks.USELESS_ROSE.get().defaultBlockState(), 1)), 64)); diff --git a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessVegetationPlacements.java b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessVegetationPlacements.java index af2f8e91..e26c2ce8 100644 --- a/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessVegetationPlacements.java +++ b/src/main/java/net/themcbrothers/uselessmod/world/worldgen/UselessVegetationPlacements.java @@ -2,7 +2,7 @@ import net.minecraft.core.HolderGetter; import net.minecraft.core.registries.Registries; -import net.minecraft.data.worldgen.BootstapContext; +import net.minecraft.data.worldgen.BootstrapContext; import net.minecraft.data.worldgen.placement.PlacementUtils; import net.minecraft.resources.ResourceKey; import net.minecraft.world.level.levelgen.feature.ConfiguredFeature; @@ -18,7 +18,7 @@ public final class UselessVegetationPlacements { public static final ResourceKey FLOWER_USELESS = PlacementUtils.createKey(UselessMod.MOD_ID + ":flower_default"); public static final ResourceKey TREES_USELESS_OAK = PlacementUtils.createKey(UselessMod.MOD_ID + ":trees_useless_oak"); - public static void bootstrap(BootstapContext context) { + public static void bootstrap(BootstrapContext context) { HolderGetter> configuredFeatures = context.lookup(Registries.CONFIGURED_FEATURE); PlacementUtils.register(context, FLOWER_USELESS, configuredFeatures.getOrThrow(UselessVegetationFeatures.USELESS_FLOWER_DEFAULT), RarityFilter.onAverageOnceEvery(32), InSquarePlacement.spread(), PlacementUtils.HEIGHTMAP, BiomeFilter.biome());