Each butterly type has its own item and throwing a butterfly in a jar will spawn a butterfly of that type where it lands
|
@ -26,7 +26,9 @@ import com.minelittlepony.unicopia.client.render.*;
|
||||||
import com.minelittlepony.unicopia.client.render.entity.*;
|
import com.minelittlepony.unicopia.client.render.entity.*;
|
||||||
import com.minelittlepony.unicopia.client.render.shader.UShaders;
|
import com.minelittlepony.unicopia.client.render.shader.UShaders;
|
||||||
import com.minelittlepony.unicopia.client.render.spell.SpellRendererFactory;
|
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.entity.mob.UEntities;
|
||||||
|
import com.minelittlepony.unicopia.item.ButterflyItem;
|
||||||
import com.minelittlepony.unicopia.item.ChameleonItem;
|
import com.minelittlepony.unicopia.item.ChameleonItem;
|
||||||
import com.minelittlepony.unicopia.item.EnchantableItem;
|
import com.minelittlepony.unicopia.item.EnchantableItem;
|
||||||
import com.minelittlepony.unicopia.item.FancyBedItem;
|
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);
|
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.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.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() {
|
ModelPredicateProviderRegistry.register(Unicopia.id("zap_cycle"), new ClampedModelPredicateProvider() {
|
||||||
private double targetAngle;
|
private double targetAngle;
|
||||||
private double lastAngle;
|
private double lastAngle;
|
||||||
|
|
|
@ -1,19 +1,25 @@
|
||||||
package com.minelittlepony.unicopia.entity.mob;
|
package com.minelittlepony.unicopia.entity.mob;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.USounds;
|
import com.minelittlepony.unicopia.USounds;
|
||||||
import com.minelittlepony.unicopia.Unicopia;
|
import com.minelittlepony.unicopia.Unicopia;
|
||||||
|
import com.minelittlepony.unicopia.item.ButterflyItem;
|
||||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||||
|
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.EntityPose;
|
import net.minecraft.entity.EntityPose;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
|
import net.minecraft.entity.ItemEntity;
|
||||||
import net.minecraft.entity.SpawnReason;
|
import net.minecraft.entity.SpawnReason;
|
||||||
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
||||||
import net.minecraft.entity.attribute.EntityAttributes;
|
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.data.TrackedDataHandlerRegistry;
|
||||||
import net.minecraft.entity.mob.AmbientEntity;
|
import net.minecraft.entity.mob.AmbientEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NbtCompound;
|
import net.minecraft.nbt.NbtCompound;
|
||||||
import net.minecraft.predicate.entity.EntityPredicates;
|
import net.minecraft.predicate.entity.EntityPredicates;
|
||||||
import net.minecraft.sound.SoundEvent;
|
import net.minecraft.sound.SoundEvent;
|
||||||
|
@ -304,6 +311,11 @@ public class ButterflyEntity extends AmbientEntity {
|
||||||
return getHeight() / 2;
|
return getHeight() / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemEntity dropStack(ItemStack stack, float yOffset) {
|
||||||
|
return super.dropStack(ButterflyItem.setVariant(stack, getVariant()), yOffset);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeCustomDataToNbt(NbtCompound nbt) {
|
public void writeCustomDataToNbt(NbtCompound nbt) {
|
||||||
super.writeCustomDataToNbt(nbt);
|
super.writeCustomDataToNbt(nbt);
|
||||||
|
@ -351,14 +363,14 @@ public class ButterflyEntity extends AmbientEntity {
|
||||||
WHITE_MONARCH,
|
WHITE_MONARCH,
|
||||||
BRIMSTONE;
|
BRIMSTONE;
|
||||||
|
|
||||||
private static final Variant[] VALUES = Variant.values();
|
public static final Variant[] VALUES = Variant.values();
|
||||||
|
private static final Map<String, Variant> 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");
|
private final Identifier skin = Unicopia.id("textures/entity/butterfly/" + name().toLowerCase() + ".png");
|
||||||
|
|
||||||
public Identifier getSkin() {
|
public Identifier getSkin() {
|
||||||
return skin;
|
return skin;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Variant byId(int index) {
|
static Variant byId(int index) {
|
||||||
return VALUES[Math.max(0, index) % VALUES.length];
|
return VALUES[Math.max(0, index) % VALUES.length];
|
||||||
}
|
}
|
||||||
|
@ -366,5 +378,9 @@ public class ButterflyEntity extends AmbientEntity {
|
||||||
static Variant random(Random rand) {
|
static Variant random(Random rand) {
|
||||||
return VALUES[rand.nextInt(VALUES.length)];
|
return VALUES[rand.nextInt(VALUES.length)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Variant byName(String name) {
|
||||||
|
return REGISTRY.getOrDefault(name == null ? "" : name, BUTTERFLY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<ItemStack> getDefaultStacks() {
|
||||||
|
return Arrays.stream(ButterflyEntity.Variant.VALUES).map(variant -> setVariant(getDefaultStack(), variant)).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,6 +2,8 @@ package com.minelittlepony.unicopia.item;
|
||||||
|
|
||||||
import com.minelittlepony.unicopia.entity.IItemEntity;
|
import com.minelittlepony.unicopia.entity.IItemEntity;
|
||||||
import com.minelittlepony.unicopia.entity.Living;
|
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 com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
|
@ -125,8 +127,16 @@ public class FilledJarItem extends JarItem implements ChameleonItem {
|
||||||
@Override
|
@Override
|
||||||
public void onImpact(MagicProjectileEntity projectile) {
|
public void onImpact(MagicProjectileEntity projectile) {
|
||||||
ItemStack stack = getAppearanceStack(projectile.getStack());
|
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()));
|
projectile.getWorld().syncWorldEvent(WorldEvents.BLOCK_BROKEN, projectile.getBlockPos(), Block.getRawIdFromState(Blocks.GLASS.getDefaultState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 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_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_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);
|
Item PALM_CHEST_BOAT = ItemGroupRegistry.register(TerraformBoatItemHelper.registerBoatItem(Unicopia.id("palm_chest_boat"), UWoodTypes.PALM_BOAT_TYPE, true), ItemGroups.FUNCTIONAL);
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/blue_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/brimstone_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,5 +2,21 @@
|
||||||
"parent": "unicopia:item/mug",
|
"parent": "unicopia:item/mug",
|
||||||
"textures": {
|
"textures": {
|
||||||
"layer0": "unicopia:item/butterfly"
|
"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" }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/green_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/hedylidae_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/lime_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/lycaenidae_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/magenta_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/monarch_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/nymphalidae_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/pink_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/purple_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/red_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/white_monarch_butterfly"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
{
|
||||||
|
"parent": "unicopia:item/mug",
|
||||||
|
"textures": {
|
||||||
|
"layer0": "unicopia:item/yellow_butterfly"
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 7.3 KiB |
Before Width: | Height: | Size: 559 B After Width: | Height: | Size: 6.6 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 7 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 7.1 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 7.5 KiB |
After Width: | Height: | Size: 7.2 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 6.8 KiB |
After Width: | Height: | Size: 7.3 KiB |
After Width: | Height: | Size: 6.8 KiB |