diff --git a/CHANGELOG.md b/CHANGELOG.md index a68d59f..b90635c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## Changelog +### 1.1.6 (2023-12-08) +- Modified sizes of butterflies so they're closer to reality +- Some butterflies will now move faster +- Butterflies now have varying rarities +- Caterpillars, chrysalises, and butterflies now have varying lifespans + ### 1.1.5 (2023-11-30) - Snow. diff --git a/README.md b/README.md index ee2e0bd..6a40380 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,16 @@ # Butterflies - This mod adds butterflies with a full life cycle to the world of Minecraft. It - features 16 butterfly species, mostly based on real-life butterflies but a - couple of them are purely fantasy butterflies. - - Butterflies will lay eggs in leaves if they get close to them, and if a player - collects these eggs they can plant them in other leaf blocks. The eggs will - eventually hatch into caterpillars. After living on the leaves for a short - time, a caterpillar will eventually build a chrysalis. These will then hatch - into new butterflies within the world. +This mod adds butterflies with a full life cycle to the world of Minecraft. It +features 16 butterfly species, mostly based on real-life butterflies but a +couple of them are purely fantasy butterflies. + +Butterflies will lay eggs in leaves if they get close to them, and if a player +collects these eggs they can plant them in other leaf blocks. The eggs will +eventually hatch into caterpillars. After living on the leaves for a short +time, a caterpillar will eventually build a chrysalis. These will then hatch +into new butterflies within the world. + +Each butterfly species has it's own size, speed, rarity and lifespan. Some will +be larger, some will move faster, some will live longer than others. Butterflies can be caught or released using a butterfly net. Once caught, they can be bottled and placed in the world as decorative objects. diff --git a/gradle.properties b/gradle.properties index 1fe53ae..df34da2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -48,7 +48,7 @@ mod_name=Butterfly Mod # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=All Rights Reserved # The mod version. See https://semver.org/ -mod_version=1.1.5 +mod_version=1.1.6 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java index a66a5bc..ac68d6c 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java +++ b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java @@ -18,10 +18,57 @@ public enum Size { LARGE } + // Represents the speed of a butterfly. + public enum Speed { + MODERATE, + FAST + } + + // Constants representing the base life spans of each butterfly cycle. + public static int LIFESPAN_SHORT = 24000 * 2; + public static int LIFESPAN_MEDIUM = 24000 * 4; + public static int LIFESPAN_LONG = 24000 * 7; + // Helper maps. private static final Map ENTITY_ID_TO_INDEX_MAP = new HashMap<>(); - private static final Map INDEX_TO_ENTITY_ID_MAP = new HashMap<>(); - private static final Map BUTTERFLY_SIZES = new HashMap<>(); + private static final Map BUTTERFLY_ENTRIES = new HashMap<>(); + + /** + * Class to hold all the data for a specific butterfly. + */ + public static class Entry { + public final String entityId; + public final Size size; + public final Speed speed; + + public final int caterpillarLifespan; + public final int chrysalisLifespan; + public final int butterflyLifespan; + + /** + * Construction + * @param entityId The id of the butterfly species. + * @param size The size of the butterfly. + * @param speed The speed of the butterfly. + * @param caterpillarLifespan How long it remains in the caterpillar stage. + * @param chrysalisLifespan How long it takes for a chrysalis to hatch. + * @param butterflyLifespan How long it lives as a butterfly. + */ + private Entry(String entityId, + Size size, + Speed speed, + int caterpillarLifespan, + int chrysalisLifespan, + int butterflyLifespan) { + this.entityId = entityId; + this.size = size; + this.speed = speed; + + this.caterpillarLifespan = caterpillarLifespan * 2; + this.chrysalisLifespan = chrysalisLifespan; + this.butterflyLifespan = butterflyLifespan * 2; + } + } /** * Create new butterfly data. @@ -30,30 +77,56 @@ public enum Size { * locations. * @param size The size of the butterfly. */ - private static void addButterfly(int index, String species, Size size) + private static void addButterfly(int index, + String species, + Size size, + Speed speed, + int caterpillarLifespan, + int chrysalisLifespan, + int butterflyLifespan) { ENTITY_ID_TO_INDEX_MAP.put(species, index); - INDEX_TO_ENTITY_ID_MAP.put(index, species); - BUTTERFLY_SIZES.put(index, size); + BUTTERFLY_ENTRIES.put(index, new Entry(species, + size, + speed, + caterpillarLifespan, + chrysalisLifespan, + butterflyLifespan)); } static { - addButterfly(0, "admiral", Size.MEDIUM); - addButterfly(1, "buckeye", Size.MEDIUM); - addButterfly(2, "cabbage", Size.LARGE); - addButterfly(3, "chalkhill", Size.SMALL); - addButterfly(4, "clipper", Size.LARGE); - addButterfly(5, "common", Size.MEDIUM); - addButterfly(6, "emperor", Size.LARGE); - addButterfly(7, "forester", Size.MEDIUM); - addButterfly(8, "glasswing", Size.MEDIUM); - addButterfly(9, "hairstreak", Size.MEDIUM); - addButterfly(10, "heath", Size.SMALL); - addButterfly(11, "longwing", Size.SMALL); - addButterfly(12, "monarch", Size.MEDIUM); - addButterfly(13, "morpho", Size.LARGE); - addButterfly(14, "rainbow", Size.SMALL); - addButterfly(15, "swallowtail", Size.LARGE); + addButterfly(0, "admiral", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + addButterfly(1, "buckeye", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(2, "cabbage", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT); + addButterfly(3, "chalkhill", Size.SMALL, Speed.FAST, + LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + addButterfly(4, "clipper", Size.LARGE, Speed.FAST, + LIFESPAN_MEDIUM, LIFESPAN_LONG, LIFESPAN_MEDIUM); + addButterfly(5, "common", Size.SMALL, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(6, "emperor", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(7, "forester", Size.SMALL, Speed.MODERATE, + LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + addButterfly(8, "glasswing", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_LONG); + addButterfly(9, "hairstreak", Size.SMALL, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT); + addButterfly(10, "heath", Size.SMALL, Speed.MODERATE, + LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_LONG); + addButterfly(11, "longwing", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_LONG); + addButterfly(12, "monarch", Size.LARGE, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(13, "morpho", Size.LARGE, Speed.MODERATE, + LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(14, "rainbow", Size.SMALL, Speed.FAST, + LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + addButterfly(15, "swallowtail", Size.LARGE, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT); } /** @@ -79,6 +152,19 @@ private static int entityIdToIndex(String entityId) { return -1; } + /** + * Converts an index to an entity ID. + * @param index The index to convert to an entity ID. + * @return The entity ID string. + */ + private static String indexToEntityId(int index) { + if (BUTTERFLY_ENTRIES.containsKey(index)) { + return BUTTERFLY_ENTRIES.get(index).entityId; + } + + return null; + } + /** * Converts a resource location to a butterfly index. * @param location The resource location to convert. @@ -95,8 +181,9 @@ public static int locationToIndex(ResourceLocation location) { * @return The resource location of the butterfly. */ public static ResourceLocation indexToButterflyLocation(int index) { - if (INDEX_TO_ENTITY_ID_MAP.containsKey(index)) { - return new ResourceLocation(ButterfliesMod.MODID, INDEX_TO_ENTITY_ID_MAP.get(index)); + String entityId = indexToEntityId(index); + if (entityId != null) { + return new ResourceLocation(ButterfliesMod.MODID, entityId); } return null; @@ -108,8 +195,9 @@ public static ResourceLocation indexToButterflyLocation(int index) { * @return The resource location of the butterfly egg. */ public static ResourceLocation indexToButterflyEggLocation(int index) { - if (INDEX_TO_ENTITY_ID_MAP.containsKey(index)) { - return new ResourceLocation(ButterfliesMod.MODID, INDEX_TO_ENTITY_ID_MAP.get(index) + "_egg"); + String entityId = indexToEntityId(index); + if (entityId != null) { + return new ResourceLocation(ButterfliesMod.MODID, entityId + "_egg"); } return null; @@ -121,8 +209,9 @@ public static ResourceLocation indexToButterflyEggLocation(int index) { * @return The resource location of the caterpillar. */ public static ResourceLocation indexToCaterpillarLocation(int index) { - if (INDEX_TO_ENTITY_ID_MAP.containsKey(index)) { - return new ResourceLocation(ButterfliesMod.MODID, INDEX_TO_ENTITY_ID_MAP.get(index) + "_caterpillar"); + String entityId = indexToEntityId(index); + if (entityId != null) { + return new ResourceLocation(ButterfliesMod.MODID, entityId + "_caterpillar"); } return null; @@ -134,23 +223,34 @@ public static ResourceLocation indexToCaterpillarLocation(int index) { * @return The resource location of the chrysalis. */ public static ResourceLocation indexToChrysalisLocation(int index) { - if (INDEX_TO_ENTITY_ID_MAP.containsKey(index)) { - return new ResourceLocation(ButterfliesMod.MODID, INDEX_TO_ENTITY_ID_MAP.get(index) + "_chrysalis"); + String entityId = indexToEntityId(index); + if (entityId != null) { + return new ResourceLocation(ButterfliesMod.MODID, entityId + "_chrysalis"); } return null; } - public static Size getSize(int index) { - if (BUTTERFLY_SIZES.containsKey(index)) { - return BUTTERFLY_SIZES.get(index); + /** + * Get butterfly data by index. + * @param index The butterfly index. + * @return The butterfly entry. + */ + public static Entry getEntry(int index) { + if (BUTTERFLY_ENTRIES.containsKey(index)) { + return BUTTERFLY_ENTRIES.get(index); } - return Size.MEDIUM; + return null; } - public static Size getSize(ResourceLocation location) { + /** + * Get butterfly data by resource location. + * @param location The resource location of the butterfly. + * @return The butterfly entry. + */ + public static Entry getEntry(ResourceLocation location) { int index = locationToIndex(location); - return getSize(index); + return getEntry(index); } } diff --git a/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Butterfly.java b/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Butterfly.java index e7ef6ac..c987e56 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Butterfly.java +++ b/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Butterfly.java @@ -1,5 +1,6 @@ package com.bokmcdok.butterflies.world.entity.animal; +import com.bokmcdok.butterflies.ButterfliesMod; import com.bokmcdok.butterflies.world.ButterflyData; import com.bokmcdok.butterflies.world.block.ButterflyLeavesBlock; import net.minecraft.core.BlockPos; @@ -66,6 +67,12 @@ public class Butterfly extends Animal { // anywhere the light level is above 8. @Nullable private BlockPos targetPosition; + // The size of the butterfly. + private final ButterflyData.Size size; + + // The speed of the butterfly. + private final double speed; + /** * Checks custom rules to determine if the entity can spawn. * @param entityType (Unused) The type of the entity to spawn. @@ -104,7 +111,7 @@ public static Butterfly createAdmiralButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_admiral.png", + "admiral", entityType, level); } @@ -119,7 +126,7 @@ public static Butterfly createBuckeyeButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_buckeye.png", + "buckeye", entityType, level); } @@ -134,7 +141,7 @@ public static Butterfly createCabbageButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_cabbage.png", + "cabbage", entityType, level); } @@ -149,7 +156,7 @@ public static Butterfly createChalkhillButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_chalkhill.png", + "chalkhill", entityType, level); } @@ -164,7 +171,7 @@ public static Butterfly createClipperButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_clipper.png", + "clipper", entityType, level); } @@ -179,7 +186,7 @@ public static Butterfly createCommonButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_common.png", + "common", entityType, level); } @@ -194,7 +201,7 @@ public static Butterfly createEmperorButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_emperor.png", + "emperor", entityType, level); } @@ -209,7 +216,7 @@ public static Butterfly createForesterButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_forester.png", + "forester", entityType, level); } @@ -224,7 +231,7 @@ public static Butterfly createGlasswingButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_glasswing.png", + "glasswing", entityType, level); } @@ -239,7 +246,7 @@ public static Butterfly createHairstreakButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_hairstreak.png", + "hairstreak", entityType, level); } @@ -254,7 +261,7 @@ public static Butterfly createHeathButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_heath.png", + "heath", entityType, level); } @@ -269,7 +276,7 @@ public static Butterfly createLongwingButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_longwing.png", + "longwing", entityType, level); } @@ -284,7 +291,7 @@ public static Butterfly createMonarchButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_monarch.png", + "monarch", entityType, level); } @@ -299,7 +306,7 @@ public static Butterfly createMorphoButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_morpho.png", entityType, level); + "morpho", entityType, level); } /** @@ -313,7 +320,7 @@ public static Butterfly createRainbowButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_rainbow.png", + "rainbow", entityType, level); } @@ -328,7 +335,7 @@ public static Butterfly createSwallowtailButterfly( EntityType entityType, Level level) { return new Butterfly( - "butterfly_swallowtail.png", + "swallowtail", entityType, level); } @@ -377,17 +384,28 @@ public static void spawn(Level level, /** * The default constructor. - * @param texture The texture the butterfly should use. + * @param species The species of the butterfly. * @param entityType The type of the entity. * @param level The level where the entity exists. */ - public Butterfly(String texture, + public Butterfly(String species, EntityType entityType, Level level) { super(entityType, level); - this.texture = new ResourceLocation( - "butterflies:textures/entity/butterfly/" + texture); + this.texture = new ResourceLocation("butterflies:textures/entity/butterfly/butterfly_" + species + ".png"); + + ResourceLocation location = new ResourceLocation(ButterfliesMod.MODID, species); + ButterflyData.Entry data = ButterflyData.getEntry(location); + this.size = data.size; + + if (data.speed == ButterflyData.Speed.FAST) { + this.speed = BUTTERFLY_SPEED * 1.2d; + } else { + this.speed = BUTTERFLY_SPEED; + } + + setAge(-data.butterflyLifespan); } /** @@ -447,6 +465,15 @@ public boolean isPushable() { return false; } + /** + * Override so that the bounding box isn't recalculated for "babies". + * @param age The age of the entity. + */ + @Override + public void setAge(int age) { + this.age = age; + } + /** * The main update loop for the entity. */ @@ -519,9 +546,9 @@ protected void customServerAiStep() { Vec3 deltaMovement = this.getDeltaMovement(); Vec3 updatedDeltaMovement = deltaMovement.add( - (Math.signum(dx) * 0.5d - deltaMovement.x) * BUTTERFLY_SPEED, + (Math.signum(dx) * 0.5d - deltaMovement.x) * this.speed, (Math.signum(dy) * 0.7d - deltaMovement.y) * 0.1d, - (Math.signum(dz) * 0.5d - deltaMovement.z) * BUTTERFLY_SPEED); + (Math.signum(dz) * 0.5d - deltaMovement.z) * this.speed); this.setDeltaMovement(updatedDeltaMovement); this.zza = 0.5f; @@ -549,6 +576,14 @@ protected void customServerAiStep() { position, EntityType.getKey(this.getType())); } + + // If the caterpillar gets too old it will die. This won't happen if it + // has been set to persistent (e.g. by using a nametag). + if (!this.isPersistenceRequired() && + this.getAge() >= 0 && + this.random.nextInt(0, 15) == 0) { + this.kill(); + } } /** @@ -577,9 +612,7 @@ protected MovementEmission getMovementEmission() { * @return A scale value based on the butterfly's size. */ public float getScale() { - ResourceLocation location = EntityType.getKey(this.getType()); - ButterflyData.Size size = ButterflyData.getSize(location); - switch (size) { + switch (this.size) { case SMALL -> { return 0.25f; } case LARGE ->{ return 0.45f; } default -> { return 0.35f; } diff --git a/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Caterpillar.java b/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Caterpillar.java index 600a2d3..3bd9772 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Caterpillar.java +++ b/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Caterpillar.java @@ -1,5 +1,6 @@ package com.bokmcdok.butterflies.world.entity.animal; +import com.bokmcdok.butterflies.ButterfliesMod; import com.bokmcdok.butterflies.world.ButterflyData; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -48,6 +49,9 @@ public class Caterpillar extends DirectionalCreature { @Nullable private Vec3 targetPosition; + // The size of the caterpillar. + private final ButterflyData.Size size; + /** * Create a Morpho butterfly * @param entityType The type of the entity. @@ -58,7 +62,7 @@ public class Caterpillar extends DirectionalCreature { public static Caterpillar createMorphoCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_morpho.png", entityType, level); + return new Caterpillar("morpho", entityType, level); } /** @@ -71,7 +75,7 @@ public static Caterpillar createMorphoCaterpillar( public static Caterpillar createForesterCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_forester.png", entityType, level); + return new Caterpillar("forester", entityType, level); } /** @@ -84,7 +88,7 @@ public static Caterpillar createForesterCaterpillar( public static Caterpillar createCommonCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_common.png", entityType, level); + return new Caterpillar("common", entityType, level); } /** @@ -97,7 +101,7 @@ public static Caterpillar createCommonCaterpillar( public static Caterpillar createEmperorCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_emperor.png", entityType, level); + return new Caterpillar("emperor", entityType, level); } /** @@ -110,7 +114,7 @@ public static Caterpillar createEmperorCaterpillar( public static Caterpillar createHairstreakCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_hairstreak.png", entityType, level); + return new Caterpillar("hairstreak", entityType, level); } /** @@ -123,7 +127,7 @@ public static Caterpillar createHairstreakCaterpillar( public static Caterpillar createRainbowCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_rainbow.png", entityType, level); + return new Caterpillar("rainbow", entityType, level); } /** @@ -136,7 +140,7 @@ public static Caterpillar createRainbowCaterpillar( public static Caterpillar createHeathCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_heath.png", entityType, level); + return new Caterpillar("heath", entityType, level); } /** @@ -149,7 +153,7 @@ public static Caterpillar createHeathCaterpillar( public static Caterpillar createGlasswingCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_glasswing.png", entityType, level); + return new Caterpillar("glasswing", entityType, level); } /** @@ -162,7 +166,7 @@ public static Caterpillar createGlasswingCaterpillar( public static Caterpillar createChalkhillCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_chalkhill.png", entityType, level); + return new Caterpillar("chalkhill", entityType, level); } /** @@ -176,7 +180,7 @@ public static Caterpillar createSwallowtailCaterpillar( EntityType entityType, Level level) { return new Caterpillar( - "caterpillar_swallowtail.png", + "swallowtail", entityType, level); } @@ -191,7 +195,7 @@ public static Caterpillar createSwallowtailCaterpillar( public static Caterpillar createMonarchCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_monarch.png", entityType, level); + return new Caterpillar("monarch", entityType, level); } /** @@ -204,7 +208,7 @@ public static Caterpillar createMonarchCaterpillar( public static Caterpillar createCabbageCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_cabbage.png", entityType, level); + return new Caterpillar("cabbage", entityType, level); } /** @@ -217,7 +221,7 @@ public static Caterpillar createCabbageCaterpillar( public static Caterpillar createAdmiralCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_admiral.png", entityType, level); + return new Caterpillar("admiral", entityType, level); } /** @@ -230,7 +234,7 @@ public static Caterpillar createAdmiralCaterpillar( public static Caterpillar createLongwingCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_longwing.png", entityType, level); + return new Caterpillar("longwing", entityType, level); } /** @@ -243,7 +247,7 @@ public static Caterpillar createLongwingCaterpillar( public static Caterpillar createClipperCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_clipper.png", entityType, level); + return new Caterpillar("clipper", entityType, level); } /** @@ -256,7 +260,7 @@ public static Caterpillar createClipperCaterpillar( public static Caterpillar createBuckeyeCaterpillar( EntityType entityType, Level level) { - return new Caterpillar("caterpillar_buckeye.png", entityType, level); + return new Caterpillar("buckeye", entityType, level); } /** @@ -302,7 +306,7 @@ public static void spawn(ServerLevel level, caterpillar.moveTo(x, y, z, 0.0F, 0.0F); caterpillar.setSurfaceDirection(direction); caterpillar.setSurfaceBlock(spawnPosition); - caterpillar.setAge(-24000); + //caterpillar.setAge(-24000); caterpillar.finalizeSpawn(level, level.getCurrentDifficultyAt(position), @@ -324,9 +328,8 @@ public float getScale() { float scale = (float)getAge() / -24000.0f; scale *= 0.04; scale += 0.08; - ResourceLocation location = EntityType.getKey(this.getType()); - ButterflyData.Size size = ButterflyData.getSize(location); - switch (size) { + + switch (this.size) { case SMALL -> { return 0.7f * scale; } case LARGE ->{ return 1.28f * scale; } default -> { return scale; } @@ -381,13 +384,19 @@ public void setAge(int age) { /** * Create a caterpillar entity. + * @param species The species of the butterfly * @param entityType The entity type. * @param level The level we are creating the entity in. */ - protected Caterpillar(String texture, + protected Caterpillar(String species, EntityType entityType, Level level) { - super("textures/entity/caterpillar/" + texture, entityType, level); + super("textures/entity/caterpillar/caterpillar_" + species + ".png", entityType, level); + + ResourceLocation location = new ResourceLocation(ButterfliesMod.MODID, species); + ButterflyData.Entry data = ButterflyData.getEntry(location); + this.size = data.size; + setAge(-data.caterpillarLifespan); } /** diff --git a/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Chrysalis.java b/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Chrysalis.java index 650a437..32399d9 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Chrysalis.java +++ b/src/main/java/com/bokmcdok/butterflies/world/entity/animal/Chrysalis.java @@ -1,5 +1,6 @@ package com.bokmcdok.butterflies.world.entity.animal; +import com.bokmcdok.butterflies.ButterfliesMod; import com.bokmcdok.butterflies.world.ButterflyData; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; @@ -35,6 +36,9 @@ public class Chrysalis extends DirectionalCreature { public static final String BUCKEYE_NAME = "buckeye_chrysalis"; public static final String CLIPPER_NAME = "clipper_chrysalis"; + // The size of the caterpillar. + private final ButterflyData.Size size; + /** * Create a Admiral chrysalis. * @@ -45,7 +49,7 @@ public class Chrysalis extends DirectionalCreature { @NotNull public static Chrysalis createAdmiral(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_admiral.png", entityType, level); + return new Chrysalis("admiral", entityType, level); } /** @@ -58,7 +62,7 @@ public static Chrysalis createAdmiral(EntityType entityType @NotNull public static Chrysalis createBuckeye(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_buckeye.png", entityType, level); + return new Chrysalis("buckeye", entityType, level); } /** @@ -71,7 +75,7 @@ public static Chrysalis createBuckeye(EntityType entityType @NotNull public static Chrysalis createCabbage(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_cabbage.png", entityType, level); + return new Chrysalis("cabbage", entityType, level); } /** @@ -84,7 +88,7 @@ public static Chrysalis createCabbage(EntityType entityType @NotNull public static Chrysalis createChalkhill(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_chalkhill.png", entityType, level); + return new Chrysalis("chalkhill", entityType, level); } /** @@ -97,7 +101,7 @@ public static Chrysalis createChalkhill(EntityType entityTy @NotNull public static Chrysalis createClipper(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_clipper.png", entityType, level); + return new Chrysalis("clipper", entityType, level); } /** @@ -110,7 +114,7 @@ public static Chrysalis createClipper(EntityType entityType @NotNull public static Chrysalis createCommon(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_common.png", entityType, level); + return new Chrysalis("common", entityType, level); } /** @@ -123,7 +127,7 @@ public static Chrysalis createCommon(EntityType entityType, @NotNull public static Chrysalis createEmperor(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_emperor.png", entityType, level); + return new Chrysalis("emperor", entityType, level); } /** @@ -136,7 +140,7 @@ public static Chrysalis createEmperor(EntityType entityType @NotNull public static Chrysalis createForester(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_forester.png", entityType, level); + return new Chrysalis("forester", entityType, level); } /** @@ -149,7 +153,7 @@ public static Chrysalis createForester(EntityType entityTyp @NotNull public static Chrysalis createGlasswing(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_glasswing.png", entityType, level); + return new Chrysalis("glasswing", entityType, level); } /** @@ -162,7 +166,7 @@ public static Chrysalis createGlasswing(EntityType entityTy @NotNull public static Chrysalis createHairstreak(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_hairstreak.png", entityType, level); + return new Chrysalis("hairstreak", entityType, level); } /** @@ -175,7 +179,7 @@ public static Chrysalis createHairstreak(EntityType entityT @NotNull public static Chrysalis createHeath(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_heath.png", entityType, level); + return new Chrysalis("heath", entityType, level); } /** @@ -188,7 +192,7 @@ public static Chrysalis createHeath(EntityType entityType, @NotNull public static Chrysalis createLongwing(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_longwing.png", entityType, level); + return new Chrysalis("longwing", entityType, level); } /** @@ -201,7 +205,7 @@ public static Chrysalis createLongwing(EntityType entityTyp @NotNull public static Chrysalis createMonarch(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_monarch.png", entityType, level); + return new Chrysalis("monarch", entityType, level); } /** @@ -214,7 +218,7 @@ public static Chrysalis createMonarch(EntityType entityType @NotNull public static Chrysalis createMorpho(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_morpho.png", entityType, level); + return new Chrysalis("morpho", entityType, level); } /** @@ -227,7 +231,7 @@ public static Chrysalis createMorpho(EntityType entityType, @NotNull public static Chrysalis createRainbow(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_rainbow.png", entityType, level); + return new Chrysalis("rainbow", entityType, level); } /** @@ -240,7 +244,7 @@ public static Chrysalis createRainbow(EntityType entityType @NotNull public static Chrysalis createSwallowtail(EntityType entityType, Level level) { - return new Chrysalis("chrysalis_swallowtail.png", entityType, level); + return new Chrysalis("swallowtail", entityType, level); } /** @@ -267,7 +271,6 @@ public static void spawn(ServerLevel level, chrysalis.setYRot(yRotation); chrysalis.setSurfaceDirection(surfaceDirection); chrysalis.setSurfaceBlock(spawnBlock); - chrysalis.setAge(-24000); chrysalis.finalizeSpawn(level, level.getCurrentDifficultyAt(spawnBlock), @@ -289,9 +292,8 @@ public float getScale() { float scale = (float)getAge() / -24000.0f; scale *= 0.06; scale += 0.1; - ResourceLocation location = EntityType.getKey(this.getType()); - ButterflyData.Size size = ButterflyData.getSize(location); - switch (size) { + + switch (this.size) { case SMALL -> { return 0.7f * scale; } case LARGE ->{ return 1.28f * scale; } default -> { return scale; } @@ -339,15 +341,19 @@ public void setAge(int age) { /** * Construction - * - * @param texture The texture used to render the entity. + * @param species The species of the butterfly * @param entityType The type of the entity. * @param level The current level. */ - protected Chrysalis(String texture, + protected Chrysalis(String species, EntityType entityType, Level level) { - super("textures/entity/chrysalis/" + texture, entityType, level); + super("textures/entity/chrysalis/chrysalis_" + species + ".png", entityType, level); + + ResourceLocation location = new ResourceLocation(ButterfliesMod.MODID, species); + ButterflyData.Entry data = ButterflyData.getEntry(location); + this.size = data.size; + setAge(-data.chrysalisLifespan); } /** diff --git a/src/main/resources/data/butterflies/forge/biome_modifier/clipper.json b/src/main/resources/data/butterflies/forge/biome_modifier/clipper.json index ccafb9d..b0d82c8 100644 --- a/src/main/resources/data/butterflies/forge/biome_modifier/clipper.json +++ b/src/main/resources/data/butterflies/forge/biome_modifier/clipper.json @@ -14,8 +14,8 @@ "spawners": { "type": "butterflies:clipper", - "weight": 10, - "minCount": 3, - "maxCount": 5 + "weight": 2, + "minCount": 1, + "maxCount": 3 } } \ No newline at end of file diff --git a/src/main/resources/data/butterflies/forge/biome_modifier/forester.json b/src/main/resources/data/butterflies/forge/biome_modifier/forester.json index 25ca93a..6d29db7 100644 --- a/src/main/resources/data/butterflies/forge/biome_modifier/forester.json +++ b/src/main/resources/data/butterflies/forge/biome_modifier/forester.json @@ -13,8 +13,8 @@ "spawners": { "type": "butterflies:forester", - "weight": 10, - "minCount": 3, - "maxCount": 5 + "weight": 2, + "minCount": 1, + "maxCount": 3 } } \ No newline at end of file diff --git a/src/main/resources/data/butterflies/forge/biome_modifier/glasswing.json b/src/main/resources/data/butterflies/forge/biome_modifier/glasswing.json index dd3ba1b..43ba4f7 100644 --- a/src/main/resources/data/butterflies/forge/biome_modifier/glasswing.json +++ b/src/main/resources/data/butterflies/forge/biome_modifier/glasswing.json @@ -12,8 +12,8 @@ "spawners": { "type": "butterflies:glasswing", - "weight": 10, - "minCount": 3, - "maxCount": 5 + "weight": 5, + "minCount": 2, + "maxCount": 4 } } \ No newline at end of file diff --git a/src/main/resources/data/butterflies/forge/biome_modifier/heath.json b/src/main/resources/data/butterflies/forge/biome_modifier/heath.json index 5e3525a..7c5273a 100644 --- a/src/main/resources/data/butterflies/forge/biome_modifier/heath.json +++ b/src/main/resources/data/butterflies/forge/biome_modifier/heath.json @@ -12,8 +12,8 @@ "spawners": { "type": "butterflies:heath", - "weight": 10, - "minCount": 3, - "maxCount": 5 + "weight": 2, + "minCount": 1, + "maxCount": 3 } } \ No newline at end of file diff --git a/src/main/resources/data/butterflies/forge/biome_modifier/morpho.json b/src/main/resources/data/butterflies/forge/biome_modifier/morpho.json index 68ada94..0e16882 100644 --- a/src/main/resources/data/butterflies/forge/biome_modifier/morpho.json +++ b/src/main/resources/data/butterflies/forge/biome_modifier/morpho.json @@ -8,8 +8,8 @@ "spawners": { "type": "butterflies:morpho", - "weight": 10, - "minCount": 3, - "maxCount": 5 + "weight": 2, + "minCount": 1, + "maxCount": 3 } } \ No newline at end of file diff --git a/src/main/resources/data/butterflies/forge/biome_modifier/rainbow.json b/src/main/resources/data/butterflies/forge/biome_modifier/rainbow.json index 41dd9ab..471b010 100644 --- a/src/main/resources/data/butterflies/forge/biome_modifier/rainbow.json +++ b/src/main/resources/data/butterflies/forge/biome_modifier/rainbow.json @@ -24,8 +24,8 @@ "spawners": { "type": "butterflies:rainbow", - "weight": 10, - "minCount": 3, - "maxCount": 5 + "weight": 5, + "minCount": 2, + "maxCount": 4 } } \ No newline at end of file