From ac320235a27a6d3ff0d8e660a1222792f4acd5e8 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Mon, 22 Jul 2024 16:22:30 -0500 Subject: [PATCH] Go Go Deferred Register... --- .../mod/ActuallyAdditions.java | 8 ++- .../mod/material/ArmorMaterials.java | 70 ++++++++----------- 2 files changed, 34 insertions(+), 44 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java index 57b9908c9..c7c09cf2a 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/ActuallyAdditions.java @@ -36,6 +36,7 @@ import de.ellpeck.actuallyadditions.mod.inventory.ActuallyContainers; import de.ellpeck.actuallyadditions.mod.items.ActuallyItems; import de.ellpeck.actuallyadditions.mod.items.Worm; import de.ellpeck.actuallyadditions.mod.lootmodifier.ActuallyLootModifiers; +import de.ellpeck.actuallyadditions.mod.material.ArmorMaterials; import de.ellpeck.actuallyadditions.mod.misc.apiimpl.LaserRelayConnectionHandler; import de.ellpeck.actuallyadditions.mod.misc.apiimpl.MethodHandler; import de.ellpeck.actuallyadditions.mod.network.PacketHandler; @@ -118,6 +119,7 @@ public class ActuallyAdditions { ActuallyComponents.init(eventBus); ActuallyLootModifiers.init(eventBus); ActuallyContainers.CONTAINERS.register(eventBus); + ArmorMaterials.init(eventBus); ENTITIES.register(eventBus); CONDITION_CODECS.register(eventBus); BIOME_MODIFIER_SERIALIZERS.register(eventBus); @@ -139,10 +141,10 @@ public class ActuallyAdditions { eventBus.addListener(this::setup); if (dist.isClient()) { - eventBus.addListener(ActuallyAdditionsClient::setup); + eventBus.addListener(ActuallyAdditionsClient::setup); eventBus.addListener(ActuallyAdditionsClient::setupMenus); - eventBus.addListener(ActuallyAdditionsClient::setupSpecialRenders); - eventBus.addListener(ActuallyAdditionsClient::registerParticleFactories); + eventBus.addListener(ActuallyAdditionsClient::setupSpecialRenders); + eventBus.addListener(ActuallyAdditionsClient::registerParticleFactories); eventBus.register(new ClientRegistryHandler()); } IFarmerBehavior.initBehaviors(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/material/ArmorMaterials.java b/src/main/java/de/ellpeck/actuallyadditions/mod/material/ArmorMaterials.java index 54241ff65..863ed2e36 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/material/ArmorMaterials.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/material/ArmorMaterials.java @@ -5,23 +5,29 @@ import net.minecraft.Util; import net.minecraft.core.Holder; import net.minecraft.core.Registry; import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.core.registries.Registries; 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.neoforged.bus.api.IEventBus; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; import java.util.EnumMap; import java.util.List; +import java.util.Map; import java.util.function.Supplier; /** * Complete copy paste from {@link net.minecraft.world.item.ArmorMaterial} *

- * todo validate all values refect correctly + * //TODO validate all values refect correctly */ public class ArmorMaterials { + public static final DeferredRegister MATERIALS = DeferredRegister.create(Registries.ARMOR_MATERIAL, ActuallyAdditions.MODID); // EMERALD("emerald_armor_material", 30, createProtectionMap( 5, 8, 9, 4 ), 15, SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 2, 0f, () -> Ingredient.fromItems(Items.EMERALD)), // OBSIDIAN("obsidian_armor_material", 28, createProtectionMap( 1, 3, 4, 3 ), 10, SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 1, 0f, () -> Ingredient.fromItems(Items.OBSIDIAN)), @@ -34,46 +40,28 @@ public class ArmorMaterials { // ENORI("enori_armor_material", 24, createProtectionMap(3, 6, 6, 3), 11, SoundEvents.ARMOR_EQUIP_GENERIC, 0, 0f, () -> Ingredient.of(ActuallyItems.ENORI_CRYSTAL.get())), // GOGGLES("goggles_armor_material", 0, createProtectionMap(0, 0, 0, 0), 0, SoundEvents.ARMOR_EQUIP_GENERIC, 0, 0f, () -> Ingredient.EMPTY); - public static final Holder GOGGLES = register( + public static final DeferredHolder GOGGLES = MATERIALS.register( "goggles_armor_material", - Util.make(new EnumMap<>(ArmorItem.Type.class), p323384 -> { - p323384.put(ArmorItem.Type.BOOTS, 0); - p323384.put(ArmorItem.Type.LEGGINGS, 0); - p323384.put(ArmorItem.Type.CHESTPLATE, 0); - p323384.put(ArmorItem.Type.HELMET, 0); - p323384.put(ArmorItem.Type.BODY, 0); - }), - 0, - SoundEvents.ARMOR_EQUIP_GENERIC, - 0.0F, - 0.0F, - () -> Ingredient.EMPTY, - List.of( - new ArmorMaterial.Layer(ActuallyAdditions.modLoc("goggles"), "", true), - new ArmorMaterial.Layer(ActuallyAdditions.modLoc("goggles"), "_overlay", false) - ) - ); + () -> new ArmorMaterial( + Map.of( + ArmorItem.Type.BOOTS, 0, + ArmorItem.Type.LEGGINGS, 0, + ArmorItem.Type.CHESTPLATE, 0, + ArmorItem.Type.HELMET, 0, + ArmorItem.Type.BODY, 0 + ), + 0, + SoundEvents.ARMOR_EQUIP_GENERIC, + () -> Ingredient.EMPTY, + List.of( + new ArmorMaterial.Layer(ActuallyAdditions.modLoc("goggles"), "", true), + new ArmorMaterial.Layer(ActuallyAdditions.modLoc("goggles"), "_overlay", false) + ), + 0.0F, + 0.0F + )); - private static Holder register( - String pName, - EnumMap pDefense, - int pEnchantmentValue, - Holder pEquipSound, - float pToughness, - float pKnockbackResistance, - Supplier pRepairIngridient, - List pLayers - ) { - EnumMap enummap = new EnumMap<>(ArmorItem.Type.class); - - for (ArmorItem.Type armoritem$type : ArmorItem.Type.values()) { - enummap.put(armoritem$type, pDefense.get(armoritem$type)); - } - - return Registry.registerForHolder( - BuiltInRegistries.ARMOR_MATERIAL, - ResourceLocation.withDefaultNamespace(pName), - new ArmorMaterial(enummap, pEnchantmentValue, pEquipSound, pRepairIngridient, pLayers, pToughness, pKnockbackResistance) - ); + public static void init(IEventBus bus) { + MATERIALS.register(bus); } -} +} \ No newline at end of file