From 8edf357aadd62b0ec58c065f56fa6fc3f16e4016 Mon Sep 17 00:00:00 2001 From: Vasco Lavos Date: Wed, 1 Dec 2021 03:51:13 +0000 Subject: [PATCH] Finish up culling --- .../base/handler/EntityAttributeHandler.java | 33 +++++++++++++++++++ .../quark/base/handler/QuarkSounds.java | 1 - .../experimental/module/ShibaModule.java | 10 +++--- .../content/mobs/module/CrabsModule.java | 6 ++-- .../content/mobs/module/ForgottenModule.java | 11 ++----- .../content/mobs/module/FoxhoundModule.java | 8 ++--- .../content/mobs/module/FrogsModule.java | 9 ++--- .../content/mobs/module/StonelingsModule.java | 9 ++--- .../content/mobs/module/ToretoiseModule.java | 9 ++--- .../content/mobs/module/WraithModule.java | 6 ++-- 10 files changed, 59 insertions(+), 43 deletions(-) create mode 100644 src/main/java/vazkii/quark/base/handler/EntityAttributeHandler.java diff --git a/src/main/java/vazkii/quark/base/handler/EntityAttributeHandler.java b/src/main/java/vazkii/quark/base/handler/EntityAttributeHandler.java new file mode 100644 index 0000000000..0acea13118 --- /dev/null +++ b/src/main/java/vazkii/quark/base/handler/EntityAttributeHandler.java @@ -0,0 +1,33 @@ +package vazkii.quark.base.handler; + +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; + +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.ai.attributes.AttributeModifierMap.MutableAttribute; +import net.minecraftforge.event.entity.EntityAttributeCreationEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +import vazkii.quark.base.Quark; + +@EventBusSubscriber(modid = Quark.MOD_ID, bus = Bus.MOD) +public final class EntityAttributeHandler { + + private static Map, Supplier> attributeSuppliers = new HashMap<>(); + + public static void put(EntityType type, Supplier attrSupplier) { + attributeSuppliers.put(type, attrSupplier); + } + + @SubscribeEvent + public static void onAttributeCreation(EntityAttributeCreationEvent event) { + for(EntityType type : attributeSuppliers.keySet()) { + Supplier supplier = attributeSuppliers.get(type); + event.put(type, supplier.get().create()); + } + } + +} diff --git a/src/main/java/vazkii/quark/base/handler/QuarkSounds.java b/src/main/java/vazkii/quark/base/handler/QuarkSounds.java index d93749193d..b9dd994fac 100644 --- a/src/main/java/vazkii/quark/base/handler/QuarkSounds.java +++ b/src/main/java/vazkii/quark/base/handler/QuarkSounds.java @@ -4,7 +4,6 @@ import com.google.common.collect.Lists; -import net.minecraft.block.SoundType; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraftforge.registries.GameData; diff --git a/src/main/java/vazkii/quark/content/experimental/module/ShibaModule.java b/src/main/java/vazkii/quark/content/experimental/module/ShibaModule.java index 118472bd81..42edb3bc02 100644 --- a/src/main/java/vazkii/quark/content/experimental/module/ShibaModule.java +++ b/src/main/java/vazkii/quark/content/experimental/module/ShibaModule.java @@ -3,7 +3,6 @@ import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntitySpawnPlacementRegistry.PlacementType; import net.minecraft.entity.EntityType; -import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.entity.passive.WolfEntity; import net.minecraft.world.gen.Heightmap.Type; @@ -12,6 +11,7 @@ import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.fml.client.registry.RenderingRegistry; import vazkii.arl.util.RegistryHelper; +import vazkii.quark.base.handler.EntityAttributeHandler; import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.ModuleCategory; import vazkii.quark.base.module.QuarkModule; @@ -41,13 +41,11 @@ public void construct() { EntitySpawnHandler.registerSpawn(this, shibaType, EntityClassification.CREATURE, PlacementType.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::canAnimalSpawn, spawnConfig); EntitySpawnHandler.addEgg(shibaType, 0xa86741, 0xe8d5b6, spawnConfig); + + EntityAttributeHandler.put(shibaType, WolfEntity::func_234233_eS_); } - @Override - public void setup() { - GlobalEntityTypeAttributes.put(shibaType, WolfEntity.func_234233_eS_().create()); - } - + @Override @OnlyIn(Dist.CLIENT) public void clientSetup() { diff --git a/src/main/java/vazkii/quark/content/mobs/module/CrabsModule.java b/src/main/java/vazkii/quark/content/mobs/module/CrabsModule.java index 2aeb8bd4f8..04d3e488e4 100644 --- a/src/main/java/vazkii/quark/content/mobs/module/CrabsModule.java +++ b/src/main/java/vazkii/quark/content/mobs/module/CrabsModule.java @@ -6,7 +6,6 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.ai.attributes.Attributes; -import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraft.item.Food; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -24,6 +23,7 @@ import vazkii.arl.util.RegistryHelper; import vazkii.quark.base.Quark; import vazkii.quark.base.handler.BrewingHandler; +import vazkii.quark.base.handler.EntityAttributeHandler; import vazkii.quark.base.item.QuarkItem; import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.ModuleCategory; @@ -90,12 +90,12 @@ public void construct() { EntitySpawnHandler.registerSpawn(this, crabType, EntityClassification.CREATURE, PlacementType.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, CrabEntity::spawnPredicate, spawnConfig); EntitySpawnHandler.addEgg(crabType, 0x893c22, 0x916548, spawnConfig); + + EntityAttributeHandler.put(crabType, CrabEntity::prepareAttributes); } @Override public void setup() { - GlobalEntityTypeAttributes.put(crabType, CrabEntity.prepareAttributes().create()); - crabSpawnableTag = BlockTags.createOptional(new ResourceLocation(Quark.MOD_ID, "crab_spawnable")); } diff --git a/src/main/java/vazkii/quark/content/mobs/module/ForgottenModule.java b/src/main/java/vazkii/quark/content/mobs/module/ForgottenModule.java index 3920dfae9f..c8704c15d0 100644 --- a/src/main/java/vazkii/quark/content/mobs/module/ForgottenModule.java +++ b/src/main/java/vazkii/quark/content/mobs/module/ForgottenModule.java @@ -4,7 +4,6 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.MobEntity; -import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraft.item.Item; import net.minecraft.util.math.vector.Vector3d; import net.minecraftforge.api.distmarker.Dist; @@ -15,6 +14,7 @@ import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.client.registry.RenderingRegistry; import vazkii.arl.util.RegistryHelper; +import vazkii.quark.base.handler.EntityAttributeHandler; import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.ModuleCategory; import vazkii.quark.base.module.QuarkModule; @@ -48,13 +48,8 @@ public void construct() { RegistryHelper.register(forgottenType, "forgotten"); EntitySpawnHandler.addEgg(forgottenType, 0x969487, 0x3a3330, this, () -> true); - } - - @Override - public void setup() { - super.setup(); - - GlobalEntityTypeAttributes.put(forgottenType, ForgottenEntity.registerAttributes().create()); + + EntityAttributeHandler.put(forgottenType, ForgottenEntity::registerAttributes); } @Override diff --git a/src/main/java/vazkii/quark/content/mobs/module/FoxhoundModule.java b/src/main/java/vazkii/quark/content/mobs/module/FoxhoundModule.java index 88c2e250e7..b993ac0c04 100644 --- a/src/main/java/vazkii/quark/content/mobs/module/FoxhoundModule.java +++ b/src/main/java/vazkii/quark/content/mobs/module/FoxhoundModule.java @@ -4,7 +4,6 @@ import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntitySpawnPlacementRegistry.PlacementType; import net.minecraft.entity.EntityType; -import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraft.entity.passive.IronGolemEntity; import net.minecraft.entity.passive.WolfEntity; import net.minecraft.tags.BlockTags; @@ -18,6 +17,7 @@ import net.minecraftforge.fml.client.registry.RenderingRegistry; import vazkii.arl.util.RegistryHelper; import vazkii.quark.base.Quark; +import vazkii.quark.base.handler.EntityAttributeHandler; import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.ModuleCategory; import vazkii.quark.base.module.QuarkModule; @@ -63,12 +63,12 @@ public void construct() { EntitySpawnHandler.track(this, foxhoundType, EntityClassification.MONSTER, lesserSpawnConfig, true); EntitySpawnHandler.addEgg(foxhoundType, 0x890d0d, 0xf2af4b, spawnConfig); + + EntityAttributeHandler.put(foxhoundType, WolfEntity::func_234233_eS_); } @Override - public void setup() { - GlobalEntityTypeAttributes.put(foxhoundType, WolfEntity.func_234233_eS_().create()); - + public void setup() { foxhoundSpawnableTag = BlockTags.createOptional(new ResourceLocation(Quark.MOD_ID, "foxhound_spawnable")); } diff --git a/src/main/java/vazkii/quark/content/mobs/module/FrogsModule.java b/src/main/java/vazkii/quark/content/mobs/module/FrogsModule.java index 329ed8c95c..f4a6645013 100644 --- a/src/main/java/vazkii/quark/content/mobs/module/FrogsModule.java +++ b/src/main/java/vazkii/quark/content/mobs/module/FrogsModule.java @@ -3,7 +3,6 @@ import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntitySpawnPlacementRegistry.PlacementType; import net.minecraft.entity.EntityType; -import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraft.entity.passive.AnimalEntity; import net.minecraft.item.Food; import net.minecraft.item.Item; @@ -15,6 +14,7 @@ import net.minecraftforge.fml.client.registry.RenderingRegistry; import vazkii.arl.util.RegistryHelper; import vazkii.quark.base.handler.BrewingHandler; +import vazkii.quark.base.handler.EntityAttributeHandler; import vazkii.quark.base.item.QuarkItem; import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.ModuleCategory; @@ -80,11 +80,8 @@ public void construct() { EntitySpawnHandler.registerSpawn(this, frogType, EntityClassification.CREATURE, PlacementType.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, AnimalEntity::canAnimalSpawn, spawnConfig); EntitySpawnHandler.addEgg(frogType, 0xbc9869, 0xffe6ad, spawnConfig); - } - - @Override - public void setup() { - GlobalEntityTypeAttributes.put(frogType, FrogEntity.prepareAttributes().create()); + + EntityAttributeHandler.put(frogType, FrogEntity::prepareAttributes); } @Override diff --git a/src/main/java/vazkii/quark/content/mobs/module/StonelingsModule.java b/src/main/java/vazkii/quark/content/mobs/module/StonelingsModule.java index e938f7163a..51582dd94b 100755 --- a/src/main/java/vazkii/quark/content/mobs/module/StonelingsModule.java +++ b/src/main/java/vazkii/quark/content/mobs/module/StonelingsModule.java @@ -3,7 +3,6 @@ import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntitySpawnPlacementRegistry.PlacementType; import net.minecraft.entity.EntityType; -import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; import net.minecraft.world.gen.Heightmap.Type; @@ -12,6 +11,7 @@ import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.fml.client.registry.RenderingRegistry; import vazkii.arl.util.RegistryHelper; +import vazkii.quark.base.handler.EntityAttributeHandler; import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.ModuleCategory; import vazkii.quark.base.module.QuarkModule; @@ -57,11 +57,8 @@ public void construct() { EntitySpawnHandler.registerSpawn(this, stonelingType, EntityClassification.MONSTER, PlacementType.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, StonelingEntity::spawnPredicate, spawnConfig); EntitySpawnHandler.addEgg(stonelingType, 0xA1A1A1, 0x505050, spawnConfig); - } - - @Override - public void setup() { - GlobalEntityTypeAttributes.put(stonelingType, StonelingEntity.prepareAttributes().create()); + + EntityAttributeHandler.put(stonelingType, StonelingEntity::prepareAttributes); } @Override diff --git a/src/main/java/vazkii/quark/content/mobs/module/ToretoiseModule.java b/src/main/java/vazkii/quark/content/mobs/module/ToretoiseModule.java index 6eae79f6d5..a9b3f8fc18 100644 --- a/src/main/java/vazkii/quark/content/mobs/module/ToretoiseModule.java +++ b/src/main/java/vazkii/quark/content/mobs/module/ToretoiseModule.java @@ -7,13 +7,13 @@ import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntitySpawnPlacementRegistry.PlacementType; import net.minecraft.entity.EntityType; -import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraft.world.gen.Heightmap.Type; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.common.BiomeDictionary; import net.minecraftforge.fml.client.registry.RenderingRegistry; import vazkii.arl.util.RegistryHelper; +import vazkii.quark.base.handler.EntityAttributeHandler; import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.ModuleCategory; import vazkii.quark.base.module.QuarkModule; @@ -61,11 +61,8 @@ public void construct() { EntitySpawnHandler.registerSpawn(this, toretoiseType, EntityClassification.MONSTER, PlacementType.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, ToretoiseEntity::spawnPredicate, spawnConfig); EntitySpawnHandler.addEgg(toretoiseType, 0x55413b, 0x383237, spawnConfig); - } - - @Override - public void setup() { - GlobalEntityTypeAttributes.put(toretoiseType, ToretoiseEntity.prepareAttributes().create()); + + EntityAttributeHandler.put(toretoiseType, ToretoiseEntity::prepareAttributes); } @Override diff --git a/src/main/java/vazkii/quark/content/mobs/module/WraithModule.java b/src/main/java/vazkii/quark/content/mobs/module/WraithModule.java index fa47b2553d..105e5df8d1 100644 --- a/src/main/java/vazkii/quark/content/mobs/module/WraithModule.java +++ b/src/main/java/vazkii/quark/content/mobs/module/WraithModule.java @@ -9,7 +9,6 @@ import net.minecraft.entity.EntityClassification; import net.minecraft.entity.EntitySpawnPlacementRegistry.PlacementType; import net.minecraft.entity.EntityType; -import net.minecraft.entity.ai.attributes.GlobalEntityTypeAttributes; import net.minecraft.entity.monster.MonsterEntity; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ITag; @@ -20,6 +19,7 @@ import net.minecraftforge.fml.client.registry.RenderingRegistry; import vazkii.arl.util.RegistryHelper; import vazkii.quark.base.Quark; +import vazkii.quark.base.handler.EntityAttributeHandler; import vazkii.quark.base.module.LoadModule; import vazkii.quark.base.module.ModuleCategory; import vazkii.quark.base.module.QuarkModule; @@ -94,12 +94,12 @@ public void construct() { EntitySpawnHandler.registerSpawn(this, wraithType, EntityClassification.MONSTER, PlacementType.ON_GROUND, Type.MOTION_BLOCKING_NO_LEAVES, MonsterEntity::canMonsterSpawnInLight, spawnConfig); EntitySpawnHandler.addEgg(wraithType, 0xececec, 0xbdbdbd, spawnConfig); + + EntityAttributeHandler.put(wraithType, WraithEntity::registerAttributes); } @Override public void setup() { - GlobalEntityTypeAttributes.put(wraithType, WraithEntity.registerAttributes().create()); - wraithSpawnableTag = BlockTags.createOptional(new ResourceLocation(Quark.MOD_ID, "wraith_spawnable")); }