Skip to content

Commit

Permalink
Merge pull request #47 from doc-bok/butterfly-stats
Browse files Browse the repository at this point in the history
[FEATURE] Individual butterfly characteristics.
  • Loading branch information
doc-bok committed Dec 8, 2023
2 parents 8ad2319 + 1034d99 commit ecb977f
Show file tree
Hide file tree
Showing 13 changed files with 291 additions and 134 deletions.
6 changes: 6 additions & 0 deletions 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.

Expand Down
21 changes: 12 additions & 9 deletions 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.
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -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
Expand Down
170 changes: 135 additions & 35 deletions src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java
Expand Up @@ -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<String, Integer> ENTITY_ID_TO_INDEX_MAP = new HashMap<>();
private static final Map<Integer, String> INDEX_TO_ENTITY_ID_MAP = new HashMap<>();
private static final Map<Integer, Size> BUTTERFLY_SIZES = new HashMap<>();
private static final Map<Integer, Entry> 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.
Expand All @@ -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);
}

/**
Expand All @@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
}
}

0 comments on commit ecb977f

Please sign in to comment.