diff --git a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java index 2d7155b2..798d7668 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java +++ b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java @@ -26,7 +26,9 @@ import com.minelittlepony.unicopia.client.render.*; import com.minelittlepony.unicopia.client.render.entity.*; import com.minelittlepony.unicopia.client.render.shader.UShaders; import com.minelittlepony.unicopia.client.render.spell.SpellRendererFactory; +import com.minelittlepony.unicopia.entity.mob.ButterflyEntity; import com.minelittlepony.unicopia.entity.mob.UEntities; +import com.minelittlepony.unicopia.item.ButterflyItem; import com.minelittlepony.unicopia.item.ChameleonItem; import com.minelittlepony.unicopia.item.EnchantableItem; import com.minelittlepony.unicopia.item.FancyBedItem; @@ -119,6 +121,7 @@ public interface URenderers { PolearmRenderer.register(UItems.WOODEN_POLEARM, UItems.STONE_POLEARM, UItems.IRON_POLEARM, UItems.GOLDEN_POLEARM, UItems.DIAMOND_POLEARM, UItems.NETHERITE_POLEARM); ModelPredicateProviderRegistry.register(UItems.GEMSTONE, new Identifier("affinity"), (stack, world, entity, seed) -> EnchantableItem.isEnchanted(stack) ? EnchantableItem.getSpellKey(stack).getAffinity().getAlignment() : 0); ModelPredicateProviderRegistry.register(UItems.ROCK_CANDY, new Identifier("count"), (stack, world, entity, seed) -> stack.getCount() / (float)stack.getMaxCount()); + ModelPredicateProviderRegistry.register(UItems.BUTTERFLY, new Identifier("variant"), (stack, world, entity, seed) -> (float)ButterflyItem.getVariant(stack).ordinal() / ButterflyEntity.Variant.VALUES.length); ModelPredicateProviderRegistry.register(Unicopia.id("zap_cycle"), new ClampedModelPredicateProvider() { private double targetAngle; private double lastAngle; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java index e16091bf..2fe5e15e 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java @@ -1,19 +1,25 @@ package com.minelittlepony.unicopia.entity.mob; +import java.util.Arrays; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.Unicopia; +import com.minelittlepony.unicopia.item.ButterflyItem; import com.minelittlepony.unicopia.util.NbtSerialisable; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityType; +import net.minecraft.entity.ItemEntity; import net.minecraft.entity.SpawnReason; import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.attribute.EntityAttributes; @@ -23,6 +29,7 @@ import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.mob.AmbientEntity; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.sound.SoundEvent; @@ -304,6 +311,11 @@ public class ButterflyEntity extends AmbientEntity { return getHeight() / 2; } + @Override + public ItemEntity dropStack(ItemStack stack, float yOffset) { + return super.dropStack(ButterflyItem.setVariant(stack, getVariant()), yOffset); + } + @Override public void writeCustomDataToNbt(NbtCompound nbt) { super.writeCustomDataToNbt(nbt); @@ -351,14 +363,14 @@ public class ButterflyEntity extends AmbientEntity { WHITE_MONARCH, BRIMSTONE; - private static final Variant[] VALUES = Variant.values(); + public static final Variant[] VALUES = Variant.values(); + private static final Map REGISTRY = Arrays.stream(VALUES).collect(Collectors.toMap(a -> a.name().toLowerCase(Locale.ROOT), Function.identity())); private final Identifier skin = Unicopia.id("textures/entity/butterfly/" + name().toLowerCase() + ".png"); public Identifier getSkin() { return skin; } - static Variant byId(int index) { return VALUES[Math.max(0, index) % VALUES.length]; } @@ -366,5 +378,9 @@ public class ButterflyEntity extends AmbientEntity { static Variant random(Random rand) { return VALUES[rand.nextInt(VALUES.length)]; } + + public static Variant byName(String name) { + return REGISTRY.getOrDefault(name == null ? "" : name, BUTTERFLY); + } } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/ButterflyItem.java b/src/main/java/com/minelittlepony/unicopia/item/ButterflyItem.java new file mode 100644 index 00000000..374838a6 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/ButterflyItem.java @@ -0,0 +1,53 @@ +package com.minelittlepony.unicopia.item; + +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import org.jetbrains.annotations.Nullable; + +import com.minelittlepony.unicopia.entity.mob.ButterflyEntity; +import com.minelittlepony.unicopia.item.group.MultiItem; + +import net.minecraft.client.item.TooltipContext; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.nbt.NbtElement; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.world.World; + +public class ButterflyItem extends Item implements MultiItem { + + public ButterflyItem(Settings settings) { + super(settings); + } + + @Override + public List getDefaultStacks() { + return Arrays.stream(ButterflyEntity.Variant.VALUES).map(variant -> setVariant(getDefaultStack(), variant)).toList(); + } + + @Override + public void appendTooltip(ItemStack stack, @Nullable World world, List tooltip, TooltipContext context) { + tooltip.add(Text.literal(getVariant(stack).name()).formatted(Formatting.LIGHT_PURPLE)); + } + + public static ButterflyEntity.Variant getVariant(ItemStack stack) { + NbtCompound nbt = stack.getNbt(); + if (nbt == null || !nbt.contains("variant", NbtElement.STRING_TYPE)) { + return ButterflyEntity.Variant.BUTTERFLY; + } + String variant = nbt.getString("variant"); + return ButterflyEntity.Variant.byName(variant); + } + + public static ItemStack setVariant(ItemStack stack, ButterflyEntity.Variant variant) { + if (stack.isOf(UItems.BUTTERFLY)) { + stack.getOrCreateNbt().putString("variant", variant.name().toLowerCase(Locale.ROOT)); + } + return stack; + } + +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/FilledJarItem.java b/src/main/java/com/minelittlepony/unicopia/item/FilledJarItem.java index 6a5b9c08..ee6dc0dc 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/FilledJarItem.java +++ b/src/main/java/com/minelittlepony/unicopia/item/FilledJarItem.java @@ -2,6 +2,8 @@ package com.minelittlepony.unicopia.item; import com.minelittlepony.unicopia.entity.IItemEntity; import com.minelittlepony.unicopia.entity.Living; +import com.minelittlepony.unicopia.entity.mob.ButterflyEntity; +import com.minelittlepony.unicopia.entity.mob.UEntities; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; import net.minecraft.block.Block; @@ -125,8 +127,16 @@ public class FilledJarItem extends JarItem implements ChameleonItem { @Override public void onImpact(MagicProjectileEntity projectile) { ItemStack stack = getAppearanceStack(projectile.getStack()); - stack.damage(1, projectile.getWorld().random, null); - projectile.dropStack(stack); + + if (stack.isOf(UItems.BUTTERFLY)) { + ButterflyEntity butterfly = UEntities.BUTTERFLY.create(projectile.getWorld()); + butterfly.setVariant(ButterflyItem.getVariant(stack)); + butterfly.updatePosition(projectile.getX(), projectile.getY(), projectile.getZ()); + projectile.getWorld().spawnEntity(butterfly); + } else { + stack.damage(1, projectile.getWorld().random, null); + projectile.dropStack(stack); + } projectile.getWorld().syncWorldEvent(WorldEvents.BLOCK_BROKEN, projectile.getBlockPos(), Block.getRawIdFromState(Blocks.GLASS.getDefaultState())); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItems.java b/src/main/java/com/minelittlepony/unicopia/item/UItems.java index cf71cf2a..5ee6baeb 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/item/UItems.java @@ -145,7 +145,7 @@ public interface UItems { Item LOOT_BUG_SPAWN_EGG = register("loot_bug_spawn_egg", new SpawnEggItem(UEntities.LOOT_BUG, 0x3C9D14, 0xE66F16, new Item.Settings()), ItemGroups.SPAWN_EGGS); Item BUTTERFLY_SPAWN_EGG = register("butterfly_spawn_egg", new SpawnEggItem(UEntities.BUTTERFLY, 0x222200, 0xAAEEFF, new Item.Settings()), ItemGroups.SPAWN_EGGS); - Item BUTTERFLY = register("butterfly", new Item(new Item.Settings().food(UFoodComponents.INSECTS)), ItemGroups.FOOD_AND_DRINK); + Item BUTTERFLY = register("butterfly", new ButterflyItem(new Item.Settings().food(UFoodComponents.INSECTS)), ItemGroups.FOOD_AND_DRINK); Item PALM_BOAT = ItemGroupRegistry.register(TerraformBoatItemHelper.registerBoatItem(Unicopia.id("palm_boat"), UWoodTypes.PALM_BOAT_TYPE, false), ItemGroups.FUNCTIONAL); Item PALM_CHEST_BOAT = ItemGroupRegistry.register(TerraformBoatItemHelper.registerBoatItem(Unicopia.id("palm_chest_boat"), UWoodTypes.PALM_BOAT_TYPE, true), ItemGroups.FUNCTIONAL); diff --git a/src/main/resources/assets/unicopia/models/item/blue_butterfly.json b/src/main/resources/assets/unicopia/models/item/blue_butterfly.json new file mode 100644 index 00000000..5006b4ce --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/blue_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/blue_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/brimstone_butterfly.json b/src/main/resources/assets/unicopia/models/item/brimstone_butterfly.json new file mode 100644 index 00000000..264d61b3 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/brimstone_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/brimstone_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/butterfly.json b/src/main/resources/assets/unicopia/models/item/butterfly.json index 9ec18ca8..875fa092 100644 --- a/src/main/resources/assets/unicopia/models/item/butterfly.json +++ b/src/main/resources/assets/unicopia/models/item/butterfly.json @@ -2,5 +2,21 @@ "parent": "unicopia:item/mug", "textures": { "layer0": "unicopia:item/butterfly" - } + }, + "overrides": [ + { "predicate": { "variant": 0.0666666666}, "model": "unicopia:item/yellow_butterfly" }, + { "predicate": { "variant": 0.1333333333}, "model": "unicopia:item/lime_butterfly" }, + { "predicate": { "variant": 0.2}, "model": "unicopia:item/red_butterfly" }, + { "predicate": { "variant": 0.2666666666}, "model": "unicopia:item/green_butterfly" }, + { "predicate": { "variant": 0.3333333333}, "model": "unicopia:item/blue_butterfly" }, + { "predicate": { "variant": 0.4}, "model": "unicopia:item/purple_butterfly" }, + { "predicate": { "variant": 0.4666666666}, "model": "unicopia:item/magenta_butterfly" }, + { "predicate": { "variant": 0.5333333333}, "model": "unicopia:item/pink_butterfly" }, + { "predicate": { "variant": 0.6}, "model": "unicopia:item/hedylidae_butterfly" }, + { "predicate": { "variant": 0.6666666666}, "model": "unicopia:item/lycaenidae_butterfly" }, + { "predicate": { "variant": 0.7333333333}, "model": "unicopia:item/nymphalidae_butterfly" }, + { "predicate": { "variant": 0.8}, "model": "unicopia:item/monarch_butterfly" }, + { "predicate": { "variant": 0.8666666666}, "model": "unicopia:item/white_monarch_butterfly" }, + { "predicate": { "variant": 0.9333333333}, "model": "unicopia:item/brimstone_butterfly" } + ] } diff --git a/src/main/resources/assets/unicopia/models/item/green_butterfly.json b/src/main/resources/assets/unicopia/models/item/green_butterfly.json new file mode 100644 index 00000000..f79317d9 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/green_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/green_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/hedylidae_butterfly.json b/src/main/resources/assets/unicopia/models/item/hedylidae_butterfly.json new file mode 100644 index 00000000..5151d763 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/hedylidae_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/hedylidae_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/lime_butterfly.json b/src/main/resources/assets/unicopia/models/item/lime_butterfly.json new file mode 100644 index 00000000..bbb36011 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/lime_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/lime_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/lycaenidae_butterfly.json b/src/main/resources/assets/unicopia/models/item/lycaenidae_butterfly.json new file mode 100644 index 00000000..e0457136 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/lycaenidae_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/lycaenidae_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/magenta_butterfly.json b/src/main/resources/assets/unicopia/models/item/magenta_butterfly.json new file mode 100644 index 00000000..dfe6072c --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/magenta_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/magenta_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/monarch_butterfly.json b/src/main/resources/assets/unicopia/models/item/monarch_butterfly.json new file mode 100644 index 00000000..895dcb56 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/monarch_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/monarch_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/nymphalidae_butterfly.json b/src/main/resources/assets/unicopia/models/item/nymphalidae_butterfly.json new file mode 100644 index 00000000..46a1dde2 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/nymphalidae_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/nymphalidae_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/pink_butterfly.json b/src/main/resources/assets/unicopia/models/item/pink_butterfly.json new file mode 100644 index 00000000..2093f6b6 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/pink_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/pink_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/purple_butterfly.json b/src/main/resources/assets/unicopia/models/item/purple_butterfly.json new file mode 100644 index 00000000..fc5a8214 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/purple_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/purple_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/red_butterfly.json b/src/main/resources/assets/unicopia/models/item/red_butterfly.json new file mode 100644 index 00000000..df49e71e --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/red_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/red_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/white_monarch_butterfly.json b/src/main/resources/assets/unicopia/models/item/white_monarch_butterfly.json new file mode 100644 index 00000000..e89aa594 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/white_monarch_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/white_monarch_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/models/item/yellow_butterfly.json b/src/main/resources/assets/unicopia/models/item/yellow_butterfly.json new file mode 100644 index 00000000..c4d12496 --- /dev/null +++ b/src/main/resources/assets/unicopia/models/item/yellow_butterfly.json @@ -0,0 +1,6 @@ +{ + "parent": "unicopia:item/mug", + "textures": { + "layer0": "unicopia:item/yellow_butterfly" + } +} diff --git a/src/main/resources/assets/unicopia/textures/item/blue_butterfly.png b/src/main/resources/assets/unicopia/textures/item/blue_butterfly.png new file mode 100644 index 00000000..ab4ea1eb Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/blue_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/brimstone_butterfly.png b/src/main/resources/assets/unicopia/textures/item/brimstone_butterfly.png new file mode 100644 index 00000000..f11ea99e Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/brimstone_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/butterfly.png b/src/main/resources/assets/unicopia/textures/item/butterfly.png index 35e5ebd6..fad1ac6d 100644 Binary files a/src/main/resources/assets/unicopia/textures/item/butterfly.png and b/src/main/resources/assets/unicopia/textures/item/butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/green_butterfly.png b/src/main/resources/assets/unicopia/textures/item/green_butterfly.png new file mode 100644 index 00000000..b645ccac Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/green_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/hedylidae_butterfly.png b/src/main/resources/assets/unicopia/textures/item/hedylidae_butterfly.png new file mode 100644 index 00000000..843ece55 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/hedylidae_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/lime_butterfly.png b/src/main/resources/assets/unicopia/textures/item/lime_butterfly.png new file mode 100644 index 00000000..efe12901 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/lime_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/lycaenidae_butterfly.png b/src/main/resources/assets/unicopia/textures/item/lycaenidae_butterfly.png new file mode 100644 index 00000000..81e81ee6 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/lycaenidae_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/magenta_butterfly.png b/src/main/resources/assets/unicopia/textures/item/magenta_butterfly.png new file mode 100644 index 00000000..d8df366a Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/magenta_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/monarch_butterfly.png b/src/main/resources/assets/unicopia/textures/item/monarch_butterfly.png new file mode 100644 index 00000000..1c7c4862 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/monarch_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/nymphalidae_butterfly.png b/src/main/resources/assets/unicopia/textures/item/nymphalidae_butterfly.png new file mode 100644 index 00000000..75365550 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/nymphalidae_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/pink_butterfly.png b/src/main/resources/assets/unicopia/textures/item/pink_butterfly.png new file mode 100644 index 00000000..384ee2d5 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/pink_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/purple_butterfly.png b/src/main/resources/assets/unicopia/textures/item/purple_butterfly.png new file mode 100644 index 00000000..79c5c4ed Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/purple_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/red_butterfly.png b/src/main/resources/assets/unicopia/textures/item/red_butterfly.png new file mode 100644 index 00000000..ff07e69b Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/red_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/white_monarch_butterfly.png b/src/main/resources/assets/unicopia/textures/item/white_monarch_butterfly.png new file mode 100644 index 00000000..62a868cf Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/white_monarch_butterfly.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/yellow_butterfly.png b/src/main/resources/assets/unicopia/textures/item/yellow_butterfly.png new file mode 100644 index 00000000..e27c9875 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/yellow_butterfly.png differ