From 94eef4f43a1ed35f259785571f2dacbdaca67a08 Mon Sep 17 00:00:00 2001 From: Sollace Date: Tue, 22 Sep 2020 12:28:44 +0200 Subject: [PATCH] Some entity refactoring --- .../unicopia/mixin/MixinStructureFeature.java | 4 +-- .../world/entity/ButterflyEntity.java | 3 -- .../unicopia/world/entity/RainbowEntity.java | 3 -- .../unicopia/world/entity/UEntities.java | 36 +++++++++++-------- .../world/entity/WildCloudEntity.java | 4 --- 5 files changed, 24 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinStructureFeature.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinStructureFeature.java index 925761ff..ccc94d9d 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinStructureFeature.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinStructureFeature.java @@ -7,8 +7,8 @@ import net.minecraft.world.gen.feature.StructureFeature; @Mixin(StructureFeature.class) public interface MixinStructureFeature { - @Invoker + @Invoker("register") static > F register(String name, F structureFeature, GenerationStep.Feature step) { - return null; + throw new NullPointerException("mixin y u fail"); } } diff --git a/src/main/java/com/minelittlepony/unicopia/world/entity/ButterflyEntity.java b/src/main/java/com/minelittlepony/unicopia/world/entity/ButterflyEntity.java index ee16ab37..f092052e 100644 --- a/src/main/java/com/minelittlepony/unicopia/world/entity/ButterflyEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/world/entity/ButterflyEntity.java @@ -25,12 +25,9 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; -import net.minecraft.world.biome.Biome.SpawnEntry; public class ButterflyEntity extends AmbientEntity { - public static final SpawnEntry SPAWN_ENTRY = new SpawnEntry(UEntities.BUTTERFLY, 15, 9, 15); - private static final TrackedData RESTING = DataTracker.registerData(ButterflyEntity.class, TrackedDataHandlerRegistry.BOOLEAN); private static final TrackedData VARIANT = DataTracker.registerData(ButterflyEntity.class, TrackedDataHandlerRegistry.INTEGER); diff --git a/src/main/java/com/minelittlepony/unicopia/world/entity/RainbowEntity.java b/src/main/java/com/minelittlepony/unicopia/world/entity/RainbowEntity.java index 55252a36..6f40e010 100644 --- a/src/main/java/com/minelittlepony/unicopia/world/entity/RainbowEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/world/entity/RainbowEntity.java @@ -18,12 +18,9 @@ import net.minecraft.util.math.Box; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; -import net.minecraft.world.biome.Biome.SpawnEntry; public class RainbowEntity extends MobEntity implements InAnimate { - public static final SpawnEntry SPAWN_ENTRY = new SpawnEntry(UEntities.RAINBOW, 1, 1, 1); - private int ticksAlive; private final double radius; diff --git a/src/main/java/com/minelittlepony/unicopia/world/entity/UEntities.java b/src/main/java/com/minelittlepony/unicopia/world/entity/UEntities.java index 56c590ae..820a0b5f 100644 --- a/src/main/java/com/minelittlepony/unicopia/world/entity/UEntities.java +++ b/src/main/java/com/minelittlepony/unicopia/world/entity/UEntities.java @@ -4,6 +4,7 @@ import java.util.List; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; +import net.fabricmc.fabric.impl.biome.InternalBiomeData; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityType; @@ -12,13 +13,9 @@ import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; -import net.minecraft.world.biome.EndBiome; -import net.minecraft.world.biome.ForestBiome; -import net.minecraft.world.biome.MountainsBiome; -import net.minecraft.world.biome.NetherWastesBiome; import net.minecraft.world.biome.OceanBiome; -import net.minecraft.world.biome.PlainsBiome; -import net.minecraft.world.biome.RiverBiome; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.Biome.SpawnEntry; public interface UEntities { EntityType SPELLBOOK = register("spellbook", FabricEntityTypeBuilder.create(SpawnGroup.MISC, SpellbookEntity::new) @@ -71,17 +68,26 @@ public interface UEntities { } static void bootstrap() { + final SpawnEntry CLOUD_SPAWN_ENTRY_LAND = new SpawnEntry(WILD_CLOUD, 1, 1, 15); + final SpawnEntry CLOUD_SPAWN_ENTRY_OCEAN = new SpawnEntry(WILD_CLOUD, 1, 1, 7); + final SpawnEntry BUTTERFLY_SPAWN_ENTRY = new SpawnEntry(BUTTERFLY, 15, 9, 15); + final SpawnEntry RAINBOW_SPAWN_ENTRY = new SpawnEntry(RAINBOW, 1, 1, 1); + Registry.BIOME.forEach(biome -> { - if (!(biome instanceof NetherWastesBiome || biome instanceof EndBiome)) { - addifAbsent(biome.getEntitySpawnList(SpawnGroup.AMBIENT), biome instanceof OceanBiome ? WildCloudEntity.SPAWN_ENTRY_OCEAN : WildCloudEntity.SPAWN_ENTRY_LAND); - addifAbsent(biome.getEntitySpawnList(SpawnGroup.CREATURE), RainbowEntity.SPAWN_ENTRY); + Biome.Category category = biome.getCategory(); + + boolean isNether = category == Biome.Category.NETHER || InternalBiomeData.getNetherBiomes().contains(biome); + + if (!isNether && category != Biome.Category.THEEND) { + addifAbsent(biome.getEntitySpawnList(SpawnGroup.AMBIENT), biome instanceof OceanBiome ? CLOUD_SPAWN_ENTRY_OCEAN : CLOUD_SPAWN_ENTRY_LAND); + addifAbsent(biome.getEntitySpawnList(SpawnGroup.CREATURE), RAINBOW_SPAWN_ENTRY); } - if (biome instanceof PlainsBiome - || biome instanceof RiverBiome - || biome instanceof MountainsBiome - || biome instanceof ForestBiome) { - addifAbsent(biome.getEntitySpawnList(SpawnGroup.AMBIENT), ButterflyEntity.SPAWN_ENTRY); + if (category == Biome.Category.PLAINS + || category == Biome.Category.RIVER + || category == Biome.Category.FOREST + || category == Biome.Category.EXTREME_HILLS) { + addifAbsent(biome.getEntitySpawnList(SpawnGroup.AMBIENT), BUTTERFLY_SPAWN_ENTRY); } }); } @@ -91,4 +97,6 @@ public interface UEntities { entries.add(entry); } } + + } diff --git a/src/main/java/com/minelittlepony/unicopia/world/entity/WildCloudEntity.java b/src/main/java/com/minelittlepony/unicopia/world/entity/WildCloudEntity.java index 1aef35c9..aba1c00f 100644 --- a/src/main/java/com/minelittlepony/unicopia/world/entity/WildCloudEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/world/entity/WildCloudEntity.java @@ -16,14 +16,10 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.LocalDifficulty; import net.minecraft.world.World; import net.minecraft.world.WorldAccess; -import net.minecraft.world.biome.Biome.SpawnEntry; import net.minecraft.world.chunk.WorldChunk; public class WildCloudEntity extends CloudEntity { - public static final SpawnEntry SPAWN_ENTRY_LAND = new SpawnEntry(UEntities.WILD_CLOUD, 1, 1, 15); - public static final SpawnEntry SPAWN_ENTRY_OCEAN = new SpawnEntry(UEntities.WILD_CLOUD, 1, 1, 7); - public WildCloudEntity(EntityType type, World world) { super(type, world);