Skip to content

Commit

Permalink
[FEATURE] Caterpillars can now be stored in jars.
Browse files Browse the repository at this point in the history
  • Loading branch information
doc-bok committed Feb 12, 2024
1 parent 49d1525 commit c0b9453
Show file tree
Hide file tree
Showing 117 changed files with 2,651 additions and 94 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,8 @@
## Changelog

### 2.4.0 (2024-02-12)
- Caterpillars can now be stored in jars.

### 2.3.0 (2024-02-08)
- Caterpillars and Chrysalises will now spawn naturally.

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=2.3.0
mod_version=2.4.0
# 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
Expand Up @@ -51,7 +51,7 @@ public static void onItemCraftedEvent(PlayerEvent.ItemCraftedEvent event) {
// Always use Entity ID for compatibility with butterfly net.
if (tag.contains(CompoundTagId.ENTITY_ID)) {
ResourceLocation location = new ResourceLocation(tag.getString(CompoundTagId.ENTITY_ID));
index = ButterflyData.locationToIndex(location);
index = ButterflyData.getButterflyIndex(location);
}

if (index >= 0) {
Expand Down Expand Up @@ -96,7 +96,7 @@ public static void onItemCraftedEvent(PlayerEvent.ItemCraftedEvent event) {
CompoundTag tag = recipeItem.getTag();
if (tag != null && tag.contains(CompoundTagId.ENTITY_ID)) {
ResourceLocation location = new ResourceLocation(tag.getString(CompoundTagId.ENTITY_ID));
index = ButterflyData.locationToIndex(location);
index = ButterflyData.getButterflyIndex(location);
break;
}
}
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.bokmcdok.butterflies.ButterfliesMod;
import com.bokmcdok.butterflies.world.block.BottledButterflyBlock;
import com.bokmcdok.butterflies.world.block.BottledCaterpillarBlock;
import com.bokmcdok.butterflies.world.block.ButterflyCherryLeavesBlock;
import com.bokmcdok.butterflies.world.block.ButterflyLeavesBlock;
import com.bokmcdok.butterflies.world.block.ButterflyMangroveLeavesBlock;
Expand Down Expand Up @@ -47,6 +48,40 @@ public class BlockRegistry {
.sound(SoundType.GLASS)
.strength(0.3F)));

// Bottled Caterpillars
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_ADMIRAL =
INSTANCE.register(BottledCaterpillarBlock.ADMIRAL_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_BUCKEYE =
INSTANCE.register(BottledCaterpillarBlock.BUCKEYE_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_CABBAGE =
INSTANCE.register(BottledCaterpillarBlock.CABBAGE_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_CHALKHILL =
INSTANCE.register(BottledCaterpillarBlock.CHALKHILL_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_CLIPPER =
INSTANCE.register(BottledCaterpillarBlock.CLIPPER_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_COMMON =
INSTANCE.register(BottledCaterpillarBlock.COMMON_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_EMPEROR =
INSTANCE.register(BottledCaterpillarBlock.EMPEROR_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_FORESTER =
INSTANCE.register(BottledCaterpillarBlock.FORESTER_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_GLASSWING =
INSTANCE.register(BottledCaterpillarBlock.GLASSWING_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_HAIRSTREAK =
INSTANCE.register(BottledCaterpillarBlock.HAIRSTREAK_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_HEATH =
INSTANCE.register(BottledCaterpillarBlock.HEATH_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_LONGWING =
INSTANCE.register(BottledCaterpillarBlock.LONGWING_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_MONARCH =
INSTANCE.register(BottledCaterpillarBlock.MONARCH_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_MORPHO =
INSTANCE.register(BottledCaterpillarBlock.MORPHO_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_RAINBOW =
INSTANCE.register(BottledCaterpillarBlock.RAINBOW_NAME, BlockRegistry::bottledCaterpillarBlock);
public static final RegistryObject<Block> BOTTLED_CATERPILLAR_SWALLOWTAIL =
INSTANCE.register(BottledCaterpillarBlock.SWALLOWTAIL_NAME, BlockRegistry::bottledCaterpillarBlock);

// Represent leaves that have butterfly eggs in them.
public static final RegistryObject<Block> BUTTERFLY_OAK_LEAVES =
INSTANCE.register("butterfly_oak_leaves", () -> butterflyLeaves(SoundType.GRASS));
Expand Down Expand Up @@ -115,6 +150,17 @@ private static ButterflyLeavesBlock butterflyLeaves(SoundType p_152615_) {
.isRedstoneConductor(BlockRegistry::never));
}

private static BottledCaterpillarBlock bottledCaterpillarBlock() {
return new BottledCaterpillarBlock(BlockBehaviour.Properties.copy(Blocks.GLASS)
.isRedstoneConductor(BlockRegistry::never)
.isSuffocating(BlockRegistry::never)
.isValidSpawn(BlockRegistry::never)
.isViewBlocking(BlockRegistry::never)
.noOcclusion()
.sound(SoundType.GLASS)
.strength(0.3F));
}

/**
* Helper method for the "never" attribute.
* @param blockState The current block state.
Expand Down
Expand Up @@ -4,6 +4,7 @@
import com.bokmcdok.butterflies.world.entity.animal.Butterfly;
import com.bokmcdok.butterflies.world.entity.animal.Caterpillar;
import com.bokmcdok.butterflies.world.item.BottledButterflyItem;
import com.bokmcdok.butterflies.world.item.BottledCaterpillarItem;
import com.bokmcdok.butterflies.world.item.ButterflyBookItem;
import com.bokmcdok.butterflies.world.item.ButterflyEggItem;
import com.bokmcdok.butterflies.world.item.ButterflyNetItem;
Expand Down Expand Up @@ -120,6 +121,40 @@ public class ItemRegistry {
public static final RegistryObject<Item> CATERPILLAR_SWALLOWTAIL = INSTANCE.register(CaterpillarItem.SWALLOWTAIL_NAME,
() -> new CaterpillarItem(Caterpillar.SWALLOWTAIL_NAME));

// Bottled Caterpillars
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_ADMIRAL = INSTANCE.register(BottledCaterpillarItem.ADMIRAL_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_ADMIRAL, Caterpillar.ADMIRAL_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_BUCKEYE = INSTANCE.register(BottledCaterpillarItem.BUCKEYE_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_BUCKEYE, Caterpillar.BUCKEYE_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_CABBAGE = INSTANCE.register(BottledCaterpillarItem.CABBAGE_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_CABBAGE, Caterpillar.CABBAGE_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_CHALKHILL = INSTANCE.register(BottledCaterpillarItem.CHALKHILL_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_CHALKHILL, Caterpillar.CHALKHILL_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_CLIPPER = INSTANCE.register(BottledCaterpillarItem.CLIPPER_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_CLIPPER, Caterpillar.CLIPPER_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_COMMON = INSTANCE.register(BottledCaterpillarItem.COMMON_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_COMMON, Caterpillar.COMMON_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_EMPEROR = INSTANCE.register(BottledCaterpillarItem.EMPEROR_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_EMPEROR, Caterpillar.EMPEROR_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_FORESTER = INSTANCE.register(BottledCaterpillarItem.FORESTER_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_FORESTER, Caterpillar.FORESTER_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_GLASSWING = INSTANCE.register(BottledCaterpillarItem.GLASSWING_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_GLASSWING, Caterpillar.GLASSWING_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_HAIRSTREAK = INSTANCE.register(BottledCaterpillarItem.HAIRSTREAK_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_HAIRSTREAK, Caterpillar.HAIRSTREAK_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_HEATH = INSTANCE.register(BottledCaterpillarItem.HEATH_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_HEATH, Caterpillar.HEATH_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_LONGWING = INSTANCE.register(BottledCaterpillarItem.LONGWING_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_LONGWING, Caterpillar.LONGWING_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_MONARCH = INSTANCE.register(BottledCaterpillarItem.MONARCH_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_MONARCH, Caterpillar.MONARCH_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_MORPHO = INSTANCE.register(BottledCaterpillarItem.MORPHO_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_MORPHO, Caterpillar.MORPHO_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_RAINBOW = INSTANCE.register(BottledCaterpillarItem.RAINBOW_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_RAINBOW, Caterpillar.RAINBOW_NAME));
public static final RegistryObject<Item> BOTTLED_CATERPILLAR_SWALLOWTAIL = INSTANCE.register(BottledCaterpillarItem.SWALLOWTAIL_NAME,
() -> new BottledCaterpillarItem(BlockRegistry.BOTTLED_CATERPILLAR_SWALLOWTAIL, Caterpillar.SWALLOWTAIL_NAME));

// Spawn eggs - Butterflies
private static final RegistryObject<Item> SPAWN_EGG_BUTTERFLY_ADMIRAL = INSTANCE.register(Butterfly.ADMIRAL_NAME,
() -> new ForgeSpawnEggItem(EntityTypeRegistry.BUTTERFLY_ADMIRAL, 0x880000, 0x0088ff, new Item.Properties()));
Expand Down Expand Up @@ -232,7 +267,6 @@ public static void registerCreativeTabContents(BuildCreativeModeTabContentsEvent
}

if (event.getTabKey() == CreativeModeTabs.NATURAL_BLOCKS) {
event.accept(BUTTERFLY_SCROLL);

event.accept(BUTTERFLY_EGG_ADMIRAL);
event.accept(BUTTERFLY_EGG_BUCKEYE);
Expand Down Expand Up @@ -272,6 +306,25 @@ public static void registerCreativeTabContents(BuildCreativeModeTabContentsEvent
if (event.getTabKey() == CreativeModeTabs.TOOLS_AND_UTILITIES) {
event.accept(BUTTERFLY_NET);
event.accept(BOTTLED_BUTTERFLY);

event.accept(BOTTLED_CATERPILLAR_ADMIRAL);
event.accept(BOTTLED_CATERPILLAR_BUCKEYE);
event.accept(BOTTLED_CATERPILLAR_CABBAGE);
event.accept(BOTTLED_CATERPILLAR_CHALKHILL);
event.accept(BOTTLED_CATERPILLAR_CLIPPER);
event.accept(BOTTLED_CATERPILLAR_COMMON);
event.accept(BOTTLED_CATERPILLAR_EMPEROR);
event.accept(BOTTLED_CATERPILLAR_FORESTER);
event.accept(BOTTLED_CATERPILLAR_GLASSWING);
event.accept(BOTTLED_CATERPILLAR_HAIRSTREAK);
event.accept(BOTTLED_CATERPILLAR_HEATH);
event.accept(BOTTLED_CATERPILLAR_LONGWING);
event.accept(BOTTLED_CATERPILLAR_MONARCH);
event.accept(BOTTLED_CATERPILLAR_MORPHO);
event.accept(BOTTLED_CATERPILLAR_RAINBOW);
event.accept(BOTTLED_CATERPILLAR_SWALLOWTAIL);

event.accept(BUTTERFLY_SCROLL);
event.accept(BUTTERFLY_BOOK);
event.accept(BUTTERFLY_ZHUANGZI);
}
Expand Down
28 changes: 21 additions & 7 deletions src/main/java/com/bokmcdok/butterflies/world/ButterflyData.java
Expand Up @@ -287,7 +287,7 @@ private static String indexToEntityId(int index) {
* @return The butterfly index for the butterfly species, or -1 if not
* found.
*/
public static int locationToIndex(ResourceLocation location) {
public static int getButterflyIndex(ResourceLocation location) {
return entityIdToIndex(location.toString());
}

Expand All @@ -296,7 +296,7 @@ public static int locationToIndex(ResourceLocation location) {
* @param index The butterfly index.
* @return The resource location of the butterfly.
*/
public static ResourceLocation indexToButterflyLocation(int index) {
public static ResourceLocation indexToButterflyEntity(int index) {
String entityId = indexToEntityId(index);
if (entityId != null) {
return new ResourceLocation(ButterfliesMod.MODID, entityId);
Expand All @@ -310,7 +310,7 @@ public static ResourceLocation indexToButterflyLocation(int index) {
* @param index The butterfly index.
* @return The resource location of the butterfly egg.
*/
public static ResourceLocation indexToButterflyEggLocation(int index) {
public static ResourceLocation indexToButterflyEggItem(int index) {
String entityId = indexToEntityId(index);
if (entityId != null) {
return new ResourceLocation(ButterfliesMod.MODID, entityId + "_egg");
Expand All @@ -324,7 +324,7 @@ public static ResourceLocation indexToButterflyEggLocation(int index) {
* @param index The butterfly index.
* @return The resource location of the caterpillar.
*/
public static ResourceLocation indexToCaterpillarLocation(int index) {
public static ResourceLocation indexToCaterpillarEntity(int index) {
String entityId = indexToEntityId(index);
if (entityId != null) {
return new ResourceLocation(ButterfliesMod.MODID, entityId + "_caterpillar");
Expand All @@ -338,7 +338,7 @@ public static ResourceLocation indexToCaterpillarLocation(int index) {
* @param index The butterfly index.
* @return The resource location of the chrysalis.
*/
public static ResourceLocation indexToChrysalisLocation(int index) {
public static ResourceLocation indexToChrysalisEntity(int index) {
String entityId = indexToEntityId(index);
if (entityId != null) {
return new ResourceLocation(ButterfliesMod.MODID, entityId + "_chrysalis");
Expand All @@ -352,7 +352,7 @@ public static ResourceLocation indexToChrysalisLocation(int index) {
* @param index The butterfly index.
* @return The resource location of the caterpillar item.
*/
public static ResourceLocation indexToCaterpillarItemLocation(int index) {
public static ResourceLocation indexToCaterpillarItem(int index) {
String entityId = indexToEntityId(index);
if (entityId != null) {
return new ResourceLocation(ButterfliesMod.MODID, "caterpillar_" + entityId);
Expand All @@ -361,6 +361,20 @@ public static ResourceLocation indexToCaterpillarItemLocation(int index) {
return null;
}

/**
* Gets the resource location for the caterpillar item at the specified index.
* @param index The butterfly index.
* @return The resource location of the caterpillar item.
*/
public static ResourceLocation indexToBottledCaterpillarItem(int index) {
String entityId = indexToEntityId(index);
if (entityId != null) {
return new ResourceLocation(ButterfliesMod.MODID, "bottled_caterpillar_" + entityId);
}

return null;
}

/**
* Get butterfly data by index.
* @param index The butterfly index.
Expand All @@ -380,7 +394,7 @@ public static ButterflyData getEntry(int index) {
* @return The butterfly entry.
*/
public static ButterflyData getEntry(ResourceLocation location) {
int index = locationToIndex(location);
int index = getButterflyIndex(location);
return getEntry(index);
}
}
Expand Up @@ -81,7 +81,7 @@ public List<ItemStack> getDrops(@NotNull BlockState blockState,
BlockEntity blockEntity = builder.getOptionalParameter(LootContextParams.BLOCK_ENTITY);
if (blockEntity instanceof ButterflyBlockEntity butterflyBlockEntity) {
ItemStack stack = new ItemStack(ItemRegistry.BOTTLED_BUTTERFLY.get());
ButterflyContainerItem.setButterfly(stack, ButterflyData.locationToIndex(butterflyBlockEntity.getEntityLocation()));
ButterflyContainerItem.setButterfly(stack, ButterflyData.getButterflyIndex(butterflyBlockEntity.getEntityLocation()));

List<ItemStack> result = Lists.newArrayList();
result.add(stack);
Expand Down

0 comments on commit c0b9453

Please sign in to comment.