From 22a44459ded51946b5325024bdcfafcc53db6398 Mon Sep 17 00:00:00 2001 From: doc-bok <41854155+doc-bok@users.noreply.github.com> Date: Fri, 8 Dec 2023 10:33:10 +0000 Subject: [PATCH 1/8] [FEATURE] Updated butterfly sizes --- .../bokmcdok/butterflies/world/ButterflyData.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java index a66a5bc..e262a8e 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java +++ b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java @@ -40,17 +40,17 @@ private static void addButterfly(int index, String species, Size size) static { addButterfly(0, "admiral", Size.MEDIUM); addButterfly(1, "buckeye", Size.MEDIUM); - addButterfly(2, "cabbage", Size.LARGE); + addButterfly(2, "cabbage", Size.MEDIUM); 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(5, "common", Size.SMALL); + addButterfly(6, "emperor", Size.MEDIUM); + addButterfly(7, "forester", Size.SMALL); addButterfly(8, "glasswing", Size.MEDIUM); - addButterfly(9, "hairstreak", Size.MEDIUM); + addButterfly(9, "hairstreak", Size.SMALL); addButterfly(10, "heath", Size.SMALL); - addButterfly(11, "longwing", Size.SMALL); - addButterfly(12, "monarch", Size.MEDIUM); + addButterfly(11, "longwing", Size.MEDIUM); + addButterfly(12, "monarch", Size.LARGE); addButterfly(13, "morpho", Size.LARGE); addButterfly(14, "rainbow", Size.SMALL); addButterfly(15, "swallowtail", Size.LARGE); From 59f6c415fac806f0058da01e7782573279323ee5 Mon Sep 17 00:00:00 2001 From: doc-bok <41854155+doc-bok@users.noreply.github.com> Date: Fri, 8 Dec 2023 11:13:15 +0000 Subject: [PATCH 2/8] [FEATURE] Fast butterflies. --- .../butterflies/world/ButterflyData.java | 127 +++++++++++++----- .../world/entity/animal/Butterfly.java | 64 +++++---- 2 files changed, 135 insertions(+), 56 deletions(-) diff --git a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java index e262a8e..04d0759 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java +++ b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java @@ -18,10 +18,26 @@ public enum Size { LARGE } + public enum Speed { + MODERATE, + FAST + } + + private static class ButterflyEntry { + public ButterflyEntry(String entityId, Size size, Speed speed) { + this.entityId = entityId; + this.size = size; + this.speed = speed; + } + + public String entityId; + public Size size; + public Speed speed; + } + // 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<>(); /** * Create new butterfly data. @@ -30,30 +46,29 @@ 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) { 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 ButterflyEntry(species, size, speed)); } static { - addButterfly(0, "admiral", Size.MEDIUM); - addButterfly(1, "buckeye", Size.MEDIUM); - addButterfly(2, "cabbage", Size.MEDIUM); - addButterfly(3, "chalkhill", Size.SMALL); - addButterfly(4, "clipper", Size.LARGE); - addButterfly(5, "common", Size.SMALL); - addButterfly(6, "emperor", Size.MEDIUM); - addButterfly(7, "forester", Size.SMALL); - addButterfly(8, "glasswing", Size.MEDIUM); - addButterfly(9, "hairstreak", Size.SMALL); - addButterfly(10, "heath", Size.SMALL); - addButterfly(11, "longwing", Size.MEDIUM); - addButterfly(12, "monarch", Size.LARGE); - addButterfly(13, "morpho", Size.LARGE); - addButterfly(14, "rainbow", Size.SMALL); - addButterfly(15, "swallowtail", Size.LARGE); + addButterfly(0, "admiral", Size.MEDIUM, Speed.MODERATE); + addButterfly(1, "buckeye", Size.MEDIUM, Speed.MODERATE); + addButterfly(2, "cabbage", Size.MEDIUM, Speed.MODERATE); + addButterfly(3, "chalkhill", Size.SMALL, Speed.FAST); + addButterfly(4, "clipper", Size.LARGE, Speed.FAST); + addButterfly(5, "common", Size.SMALL, Speed.MODERATE); + addButterfly(6, "emperor", Size.MEDIUM, Speed.MODERATE); + addButterfly(7, "forester", Size.SMALL, Speed.MODERATE); + addButterfly(8, "glasswing", Size.MEDIUM, Speed.MODERATE); + addButterfly(9, "hairstreak", Size.SMALL, Speed.MODERATE); + addButterfly(10, "heath", Size.SMALL, Speed.MODERATE); + addButterfly(11, "longwing", Size.MEDIUM, Speed.MODERATE); + addButterfly(12, "monarch", Size.LARGE, Speed.MODERATE); + addButterfly(13, "morpho", Size.LARGE, Speed.MODERATE); + addButterfly(14, "rainbow", Size.SMALL, Speed.FAST); + addButterfly(15, "swallowtail", Size.LARGE, Speed.MODERATE); } /** @@ -79,6 +94,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 +123,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 +137,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 +151,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 +165,57 @@ 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; } + /** + * Get the size of the butterfly by index. + * @param index The butterfly index. + * @return The size of the butterfly. + */ public static Size getSize(int index) { - if (BUTTERFLY_SIZES.containsKey(index)) { - return BUTTERFLY_SIZES.get(index); + if (BUTTERFLY_ENTRIES.containsKey(index)) { + return BUTTERFLY_ENTRIES.get(index).size; } return Size.MEDIUM; } + /** + * Get the size of the butterfly by its resource location. + * @param location The resource location of the butterfly. + * @return The size of the butterfly. + */ public static Size getSize(ResourceLocation location) { int index = locationToIndex(location); return getSize(index); } + + /** + * Get the speed of the butterfly by index. + * @param index The butterfly index. + * @return The speed of the butterfly. + */ + public static Speed getSpeed(int index) { + if (BUTTERFLY_ENTRIES.containsKey(index)) { + return BUTTERFLY_ENTRIES.get(index).speed; + } + + return Speed.MODERATE; + } + + /** + * Get the speed of the butterfly by its resource location. + * @param location The resource location of the butterfly. + * @return The speed of the butterfly. + */ + public static Speed getSpeed(ResourceLocation location) { + int index = locationToIndex(location); + return getSpeed(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..eeee1e5 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 ButterflyData.Size size; + + // The speed of the butterfly. + private 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,26 @@ 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); + + this.size = ButterflyData.getSize(location); + + this.speed = BUTTERFLY_SPEED; + ButterflyData.Speed speed = ButterflyData.getSpeed(location); + if (speed == ButterflyData.Speed.FAST) { + this.speed *= 1.2d; + } } /** @@ -519,9 +535,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; @@ -577,9 +593,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; } From b5ec5b20f25740ef3d224a6e2198c0b5885eb18c Mon Sep 17 00:00:00 2001 From: doc-bok <41854155+doc-bok@users.noreply.github.com> Date: Fri, 8 Dec 2023 11:17:50 +0000 Subject: [PATCH 3/8] [FEATURE] Rare butterflies --- .../data/butterflies/forge/biome_modifier/clipper.json | 6 +++--- .../data/butterflies/forge/biome_modifier/forester.json | 6 +++--- .../data/butterflies/forge/biome_modifier/glasswing.json | 6 +++--- .../data/butterflies/forge/biome_modifier/heath.json | 6 +++--- .../data/butterflies/forge/biome_modifier/morpho.json | 6 +++--- .../data/butterflies/forge/biome_modifier/rainbow.json | 6 +++--- 6 files changed, 18 insertions(+), 18 deletions(-) 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 From 366a851a90fbaf99c6101fee024db0a880fd0580 Mon Sep 17 00:00:00 2001 From: doc-bok <41854155+doc-bok@users.noreply.github.com> Date: Fri, 8 Dec 2023 15:34:44 +0000 Subject: [PATCH 4/8] [FEATURE] Added lifespan statistic. --- .../butterflies/world/ButterflyData.java | 136 +++++++++++------- .../world/entity/animal/Butterfly.java | 15 +- .../world/entity/animal/Caterpillar.java | 50 ++++--- .../world/entity/animal/Chrysalis.java | 52 ++++--- 4 files changed, 149 insertions(+), 104 deletions(-) diff --git a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java index 04d0759..86643ba 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java +++ b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java @@ -18,26 +18,50 @@ public enum Size { LARGE } + // Represents the speed of a butterfly. public enum Speed { MODERATE, FAST } - private static class ButterflyEntry { - public ButterflyEntry(String entityId, Size size, Speed speed) { + public static int LIFESPAN_SHORT = 24000 * 2; + public static int LIFESPAN_MEDIUM = 24000 * 5; + public static int LIFESPAN_LONG = 24000 * 7; + + /** + * Class to hold all the data for a specific butterfly. + */ + public static class Entry { + private Entry(String entityId, + Size size, + Speed speed, + int eggLifespan, + int caterpillarLifespan, + int chrysalisLifespan, + int butterflyLifespan) { this.entityId = entityId; this.size = size; this.speed = speed; + + this.eggLifespan = eggLifespan; + this.caterpillarLifespan = caterpillarLifespan *2; + this.chrysalisLifespan = chrysalisLifespan; + this.butterflyLifespan = butterflyLifespan * 2; } public String entityId; public Size size; public Speed speed; + + public int eggLifespan; + public int caterpillarLifespan; + public int chrysalisLifespan; + public int butterflyLifespan; } // Helper maps. private static final Map ENTITY_ID_TO_INDEX_MAP = new HashMap<>(); - private static final Map BUTTERFLY_ENTRIES = new HashMap<>(); + private static final Map BUTTERFLY_ENTRIES = new HashMap<>(); /** * Create new butterfly data. @@ -46,29 +70,58 @@ public ButterflyEntry(String entityId, Size size, Speed speed) { * locations. * @param size The size of the butterfly. */ - private static void addButterfly(int index, String species, Size size, Speed speed) + private static void addButterfly(int index, + String species, + Size size, + Speed speed, + int eggLifespan, + int caterpillarLifespan, + int chrysalisLifespan, + int butterflyLifespan) { ENTITY_ID_TO_INDEX_MAP.put(species, index); - BUTTERFLY_ENTRIES.put(index, new ButterflyEntry(species, size, speed)); + BUTTERFLY_ENTRIES.put(index, new Entry(species, + size, + speed, + eggLifespan, + caterpillarLifespan, + chrysalisLifespan, + butterflyLifespan)); } static { - addButterfly(0, "admiral", Size.MEDIUM, Speed.MODERATE); - addButterfly(1, "buckeye", Size.MEDIUM, Speed.MODERATE); - addButterfly(2, "cabbage", Size.MEDIUM, Speed.MODERATE); - addButterfly(3, "chalkhill", Size.SMALL, Speed.FAST); - addButterfly(4, "clipper", Size.LARGE, Speed.FAST); - addButterfly(5, "common", Size.SMALL, Speed.MODERATE); - addButterfly(6, "emperor", Size.MEDIUM, Speed.MODERATE); - addButterfly(7, "forester", Size.SMALL, Speed.MODERATE); - addButterfly(8, "glasswing", Size.MEDIUM, Speed.MODERATE); - addButterfly(9, "hairstreak", Size.SMALL, Speed.MODERATE); - addButterfly(10, "heath", Size.SMALL, Speed.MODERATE); - addButterfly(11, "longwing", Size.MEDIUM, Speed.MODERATE); - addButterfly(12, "monarch", Size.LARGE, Speed.MODERATE); - addButterfly(13, "morpho", Size.LARGE, Speed.MODERATE); - addButterfly(14, "rainbow", Size.SMALL, Speed.FAST); - addButterfly(15, "swallowtail", Size.LARGE, Speed.MODERATE); + addButterfly(0, "admiral", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + addButterfly(1, "buckeye", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(2, "cabbage", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT); + addButterfly(3, "chalkhill", Size.SMALL, Speed.FAST, + LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + addButterfly(4, "clipper", Size.LARGE, Speed.FAST, + LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_LONG, LIFESPAN_MEDIUM); + addButterfly(5, "common", Size.SMALL, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(6, "emperor", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(7, "forester", Size.SMALL, Speed.MODERATE, + LIFESPAN_MEDIUM, LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + addButterfly(8, "glasswing", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_LONG); + addButterfly(9, "hairstreak", Size.SMALL, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT); + addButterfly(10, "heath", Size.SMALL, Speed.MODERATE, + LIFESPAN_MEDIUM, LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_LONG); + addButterfly(11, "longwing", Size.MEDIUM, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_LONG); + addButterfly(12, "monarch", Size.LARGE, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(13, "morpho", Size.LARGE, Speed.MODERATE, + LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + addButterfly(14, "rainbow", Size.SMALL, Speed.FAST, + LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + addButterfly(15, "swallowtail", Size.LARGE, Speed.MODERATE, + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT); } /** @@ -174,48 +227,25 @@ public static ResourceLocation indexToChrysalisLocation(int index) { } /** - * Get the size of the butterfly by index. - * @param index The butterfly index. - * @return The size of the butterfly. - */ - public static Size getSize(int index) { - if (BUTTERFLY_ENTRIES.containsKey(index)) { - return BUTTERFLY_ENTRIES.get(index).size; - } - - return Size.MEDIUM; - } - - /** - * Get the size of the butterfly by its resource location. - * @param location The resource location of the butterfly. - * @return The size of the butterfly. - */ - public static Size getSize(ResourceLocation location) { - int index = locationToIndex(location); - return getSize(index); - } - - /** - * Get the speed of the butterfly by index. + * Get butterfly data by index. * @param index The butterfly index. - * @return The speed of the butterfly. + * @return The butterfly entry. */ - public static Speed getSpeed(int index) { + public static Entry getEntry(int index) { if (BUTTERFLY_ENTRIES.containsKey(index)) { - return BUTTERFLY_ENTRIES.get(index).speed; + return BUTTERFLY_ENTRIES.get(index); } - return Speed.MODERATE; + return null; } /** - * Get the speed of the butterfly by its resource location. + * Get butterfly data by resource location. * @param location The resource location of the butterfly. - * @return The speed of the butterfly. + * @return The butterfly entry. */ - public static Speed getSpeed(ResourceLocation location) { + public static Entry getEntry(ResourceLocation location) { int index = locationToIndex(location); - return getSpeed(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 eeee1e5..d785af6 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 @@ -68,10 +68,10 @@ public class Butterfly extends Animal { @Nullable private BlockPos targetPosition; // The size of the butterfly. - private ButterflyData.Size size; + private final ButterflyData.Size size; // The speed of the butterfly. - private double speed; + private final double speed; /** * Checks custom rules to determine if the entity can spawn. @@ -396,13 +396,14 @@ public Butterfly(String species, 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; - this.size = ButterflyData.getSize(location); - - this.speed = BUTTERFLY_SPEED; - ButterflyData.Speed speed = ButterflyData.getSpeed(location); + ButterflyData.Speed speed = data.speed; if (speed == ButterflyData.Speed.FAST) { - this.speed *= 1.2d; + this.speed = BUTTERFLY_SPEED * 1.2d; + } else { + this.speed = BUTTERFLY_SPEED; } } 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..dfe24a4 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); } /** @@ -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,18 @@ 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("butterflies:textures/entity/butterfly/caterpillar_" + species + ".png", entityType, level); + + ResourceLocation location = new ResourceLocation(ButterfliesMod.MODID, species); + ButterflyData.Entry data = ButterflyData.getEntry(location); + this.size = data.size; } /** 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..57541f3 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); } /** @@ -289,9 +293,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 +342,18 @@ 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("butterflies:textures/entity/butterfly/chrysalis_" + species + ".png", entityType, level); + + ResourceLocation location = new ResourceLocation(ButterfliesMod.MODID, species); + ButterflyData.Entry data = ButterflyData.getEntry(location); + this.size = data.size; } /** From a00fd6d2dfc05bc5dc7c3ca6828e3628ddf42bd7 Mon Sep 17 00:00:00 2001 From: doc-bok <41854155+doc-bok@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:13:09 +0000 Subject: [PATCH 5/8] [FEATURE] Chrysalis and caterpillar lifespans --- .../java/com/bokmcdok/butterflies/world/ButterflyData.java | 2 +- .../butterflies/world/entity/animal/Caterpillar.java | 5 +++-- .../bokmcdok/butterflies/world/entity/animal/Chrysalis.java | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java index 86643ba..386a0e2 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java +++ b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java @@ -25,7 +25,7 @@ public enum Speed { } public static int LIFESPAN_SHORT = 24000 * 2; - public static int LIFESPAN_MEDIUM = 24000 * 5; + public static int LIFESPAN_MEDIUM = 24000 * 4; public static int LIFESPAN_LONG = 24000 * 7; /** 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 dfe24a4..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 @@ -306,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), @@ -391,11 +391,12 @@ public void setAge(int age) { protected Caterpillar(String species, EntityType entityType, Level level) { - super("butterflies:textures/entity/butterfly/caterpillar_" + species + ".png", 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 57541f3..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 @@ -271,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), @@ -349,11 +348,12 @@ public void setAge(int age) { protected Chrysalis(String species, EntityType entityType, Level level) { - super("butterflies:textures/entity/butterfly/chrysalis_" + species + ".png", 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); } /** From 1071612b8243ad6ea50a256258309f738ea6ae39 Mon Sep 17 00:00:00 2001 From: doc-bok <41854155+doc-bok@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:39:00 +0000 Subject: [PATCH 6/8] [FEATURE] Butterfly lifespan --- .../butterflies/world/ButterflyData.java | 3 ++- .../world/entity/animal/Butterfly.java | 22 +++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java index 386a0e2..9ca01ac 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java +++ b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java @@ -24,6 +24,7 @@ public enum Speed { 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; @@ -44,7 +45,7 @@ private Entry(String entityId, this.speed = speed; this.eggLifespan = eggLifespan; - this.caterpillarLifespan = caterpillarLifespan *2; + this.caterpillarLifespan = caterpillarLifespan * 2; this.chrysalisLifespan = chrysalisLifespan; this.butterflyLifespan = butterflyLifespan * 2; } 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 d785af6..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 @@ -399,12 +399,13 @@ public Butterfly(String species, ButterflyData.Entry data = ButterflyData.getEntry(location); this.size = data.size; - ButterflyData.Speed speed = data.speed; - if (speed == ButterflyData.Speed.FAST) { + if (data.speed == ButterflyData.Speed.FAST) { this.speed = BUTTERFLY_SPEED * 1.2d; } else { this.speed = BUTTERFLY_SPEED; } + + setAge(-data.butterflyLifespan); } /** @@ -464,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. */ @@ -566,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(); + } } /** From b9e2411b0e49bd13467b0cb6e9a7519b5275edc2 Mon Sep 17 00:00:00 2001 From: doc-bok <41854155+doc-bok@users.noreply.github.com> Date: Fri, 8 Dec 2023 17:55:36 +0000 Subject: [PATCH 7/8] [FEATURE] Updated changelist --- CHANGELOG.md | 6 +++ README.md | 21 ++++---- gradle.properties | 2 +- .../butterflies/world/ButterflyData.java | 49 +++++++++---------- 4 files changed, 41 insertions(+), 37 deletions(-) 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 9ca01ac..f583f6c 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java +++ b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java @@ -36,7 +36,6 @@ public static class Entry { private Entry(String entityId, Size size, Speed speed, - int eggLifespan, int caterpillarLifespan, int chrysalisLifespan, int butterflyLifespan) { @@ -44,20 +43,18 @@ private Entry(String entityId, this.size = size; this.speed = speed; - this.eggLifespan = eggLifespan; this.caterpillarLifespan = caterpillarLifespan * 2; this.chrysalisLifespan = chrysalisLifespan; this.butterflyLifespan = butterflyLifespan * 2; } - public String entityId; - public Size size; - public Speed speed; + public final String entityId; + public final Size size; + public final Speed speed; - public int eggLifespan; - public int caterpillarLifespan; - public int chrysalisLifespan; - public int butterflyLifespan; + public final int caterpillarLifespan; + public final int chrysalisLifespan; + public final int butterflyLifespan; } // Helper maps. @@ -75,7 +72,6 @@ private static void addButterfly(int index, String species, Size size, Speed speed, - int eggLifespan, int caterpillarLifespan, int chrysalisLifespan, int butterflyLifespan) @@ -84,7 +80,6 @@ private static void addButterfly(int index, BUTTERFLY_ENTRIES.put(index, new Entry(species, size, speed, - eggLifespan, caterpillarLifespan, chrysalisLifespan, butterflyLifespan)); @@ -92,37 +87,37 @@ private static void addButterfly(int index, static { addButterfly(0, "admiral", Size.MEDIUM, Speed.MODERATE, - LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); addButterfly(1, "buckeye", Size.MEDIUM, Speed.MODERATE, - LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); addButterfly(2, "cabbage", Size.MEDIUM, Speed.MODERATE, - LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT); + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT); addButterfly(3, "chalkhill", Size.SMALL, Speed.FAST, - LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); addButterfly(4, "clipper", Size.LARGE, Speed.FAST, - LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_LONG, LIFESPAN_MEDIUM); + LIFESPAN_MEDIUM, LIFESPAN_LONG, LIFESPAN_MEDIUM); addButterfly(5, "common", Size.SMALL, Speed.MODERATE, - LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); addButterfly(6, "emperor", Size.MEDIUM, Speed.MODERATE, - LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM); addButterfly(7, "forester", Size.SMALL, Speed.MODERATE, - LIFESPAN_MEDIUM, LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); addButterfly(8, "glasswing", Size.MEDIUM, Speed.MODERATE, - LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_LONG); + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_LONG); addButterfly(9, "hairstreak", Size.SMALL, Speed.MODERATE, - LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT); + LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT); addButterfly(10, "heath", Size.SMALL, Speed.MODERATE, - LIFESPAN_MEDIUM, LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_LONG); + LIFESPAN_LONG, LIFESPAN_MEDIUM, LIFESPAN_LONG); addButterfly(11, "longwing", Size.MEDIUM, Speed.MODERATE, - LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_LONG); + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_LONG); addButterfly(12, "monarch", Size.LARGE, Speed.MODERATE, - LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM); addButterfly(13, "morpho", Size.LARGE, Speed.MODERATE, - LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM); + LIFESPAN_MEDIUM, LIFESPAN_SHORT, LIFESPAN_MEDIUM); addButterfly(14, "rainbow", Size.SMALL, Speed.FAST, - LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); + LIFESPAN_MEDIUM, LIFESPAN_MEDIUM, LIFESPAN_MEDIUM); addButterfly(15, "swallowtail", Size.LARGE, Speed.MODERATE, - LIFESPAN_SHORT, LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT); + LIFESPAN_SHORT, LIFESPAN_MEDIUM, LIFESPAN_SHORT); } /** From 1034d997b99e028fbee3afa572466e83dc79347b Mon Sep 17 00:00:00 2001 From: doc-bok <41854155+doc-bok@users.noreply.github.com> Date: Fri, 8 Dec 2023 18:37:19 +0000 Subject: [PATCH 8/8] [FIX] Formatting issues --- .../butterflies/world/ButterflyData.java | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java index f583f6c..ac68d6c 100644 --- a/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java +++ b/src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java @@ -29,16 +29,37 @@ public enum Speed { 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 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) { + Size size, + Speed speed, + int caterpillarLifespan, + int chrysalisLifespan, + int butterflyLifespan) { this.entityId = entityId; this.size = size; this.speed = speed; @@ -47,20 +68,8 @@ private Entry(String entityId, this.chrysalisLifespan = chrysalisLifespan; this.butterflyLifespan = butterflyLifespan * 2; } - - public final String entityId; - public final Size size; - public final Speed speed; - - public final int caterpillarLifespan; - public final int chrysalisLifespan; - public final int butterflyLifespan; } - // Helper maps. - private static final Map ENTITY_ID_TO_INDEX_MAP = new HashMap<>(); - private static final Map BUTTERFLY_ENTRIES = new HashMap<>(); - /** * Create new butterfly data. * @param index The butterfly index.