diff --git a/src/main/java/com/minelittlepony/unicopia/client/ModifierTooltipRenderer.java b/src/main/java/com/minelittlepony/unicopia/client/ModifierTooltipRenderer.java index 6d0f7edf..38011ff6 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/ModifierTooltipRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/client/ModifierTooltipRenderer.java @@ -36,6 +36,7 @@ public class ModifierTooltipRenderer { appendTooltip(stack, UDataComponentTypes.CHARGES, context, textConsumer, type); appendTooltip(stack, UDataComponentTypes.ISSUER, context, textConsumer, type); appendTooltip(stack, UDataComponentTypes.BUTTERFLY_VARIANT, context, textConsumer, type); + appendTooltip(stack, UDataComponentTypes.BALLOON_DESIGN, context, textConsumer, type); EnchantableItem.getSpellEffect(stack).appendTooltip(context, textConsumer, type); if (GlowableItem.isGlowing(stack)) { textConsumer.accept(Text.translatable("item.unicopia.friendship_bracelet.glowing").formatted(Formatting.ITALIC, Formatting.GRAY)); diff --git a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java index 8f518a0a..46333fe3 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/URenderers.java +++ b/src/main/java/com/minelittlepony/unicopia/client/URenderers.java @@ -28,12 +28,14 @@ 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.AirBalloonEntity; import com.minelittlepony.unicopia.entity.mob.ButterflyEntity; import com.minelittlepony.unicopia.entity.mob.UEntities; import com.minelittlepony.unicopia.item.EnchantableItem; import com.minelittlepony.unicopia.item.FancyBedItem; import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.component.Appearance; +import com.minelittlepony.unicopia.item.component.BalloonDesignComponent; import com.minelittlepony.unicopia.item.component.BufferflyVariantComponent; import com.minelittlepony.unicopia.particle.UParticles; import com.terraformersmc.terraform.boat.api.client.TerraformBoatClientHelper; @@ -132,6 +134,7 @@ public interface URenderers { ModelPredicateProviderRegistry.register(UItems.GEMSTONE, Identifier.ofVanilla("shape"), (stack, world, entity, seed) -> EnchantableItem.getSpellKey(stack).getGemShape().getId()); ModelPredicateProviderRegistry.register(UItems.ROCK_CANDY, Identifier.ofVanilla("count"), (stack, world, entity, seed) -> stack.getCount() / (float)stack.getMaxCount()); ModelPredicateProviderRegistry.register(UItems.BUTTERFLY, Identifier.ofVanilla("variant"), (stack, world, entity, seed) -> (float)BufferflyVariantComponent.get(stack).variant().ordinal() / ButterflyEntity.Variant.VALUES.length); + ModelPredicateProviderRegistry.register(UItems.GIANT_BALLOON, Identifier.ofVanilla("design"), (stack, world, entity, seed) -> (float)BalloonDesignComponent.get(stack).design().ordinal() / AirBalloonEntity.BalloonDesign.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/datagen/providers/ItemModels.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/ItemModels.java index 5cf0dc60..f919c717 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/ItemModels.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/ItemModels.java @@ -6,6 +6,7 @@ import java.util.Optional; import com.google.common.base.Strings; import com.minelittlepony.unicopia.Unicopia; +import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity; import com.minelittlepony.unicopia.entity.mob.ButterflyEntity; import net.minecraft.data.client.ItemModelGenerator; import net.minecraft.data.client.Model; @@ -64,6 +65,15 @@ interface ItemModels { }).upload(item, itemModelGenerator); } + static void registerBalloonDesigns(ItemModelGenerator itemModelGenerator, Item item) { + float step = 1F / AirBalloonEntity.BalloonDesign.VALUES.length; + ModelOverrides.of(GENERATED).addUniform("design", step, 1, step, (i, value) -> { + String name = AirBalloonEntity.BalloonDesign.getType(i + 1).name().toLowerCase(Locale.ROOT); + Identifier subModelId = Registries.ITEM.getId(item).withPath(p -> "item/" + name + "_" + p); + return GENERATED.upload(subModelId, TextureMap.layer0(subModelId), itemModelGenerator.writer); + }).upload(item, itemModelGenerator); + } + static void registerSpectralBlock(ItemModelGenerator itemModelGenerator, Item item) { final float step = 0.025F; String[] suffexes = { "", "_greening", "_flowering", "_fruiting", "_ripe", "" }; diff --git a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UModelProvider.java b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UModelProvider.java index ed092815..5d4b9269 100644 --- a/src/main/java/com/minelittlepony/unicopia/datagen/providers/UModelProvider.java +++ b/src/main/java/com/minelittlepony/unicopia/datagen/providers/UModelProvider.java @@ -75,7 +75,7 @@ public class UModelProvider extends FabricModelProvider { UItems.DAFFODIL_DAISY_SANDWICH, UItems.DRAGON_BREATH_SCROLL, UItems.EMPTY_JAR, UItems.FRIENDSHIP_BRACELET, UItems.FRIED_AXOLOTL, UItems.FROG_LEGS, - UItems.GIANT_BALLOON, UItems.GOLDEN_FEATHER, UItems.GOLDEN_OAK_SEEDS, UItems.GOLDEN_WING, UItems.GREEN_APPLE_SEEDS, UItems.GREEN_APPLE, UItems.GROGARS_BELL, + UItems.GOLDEN_FEATHER, UItems.GOLDEN_OAK_SEEDS, UItems.GOLDEN_WING, UItems.GREEN_APPLE_SEEDS, UItems.GREEN_APPLE, UItems.GROGARS_BELL, UItems.GRYPHON_FEATHER, UItems.GREEN_FRIED_EGG, UItems.HAY_BURGER, UItems.HAY_FRIES, UItems.HORSE_SHOE_FRIES, UItems.IMPORTED_OATS, @@ -131,8 +131,8 @@ public class UModelProvider extends FabricModelProvider { .flatMap(id -> Registries.ITEM.getOrEmpty(id).stream()) .toArray(Item[]::new)); - // butterflies ItemModels.registerButterfly(itemModelGenerator, UItems.BUTTERFLY); + ItemModels.registerBalloonDesigns(itemModelGenerator, UItems.GIANT_BALLOON); ItemModels.registerSpectralBlock(itemModelGenerator, UItems.SPECTRAL_CLOCK); ModelOverrides.of(ItemModels.GENERATED) .addUniform("count", 2, 16, ModelIds.getItemModelId(UItems.ROCK_CANDY)) diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java index 058b2cb3..d070f311 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/AirBalloonEntity.java @@ -54,6 +54,7 @@ import com.minelittlepony.unicopia.entity.collision.MultiBoundingBoxEntity; import com.minelittlepony.unicopia.entity.collision.MultiBox; import com.minelittlepony.unicopia.item.BasketItem; import com.minelittlepony.unicopia.item.UItems; +import com.minelittlepony.unicopia.item.component.BalloonDesignComponent; import com.minelittlepony.unicopia.item.component.UDataComponentTypes; import com.minelittlepony.unicopia.server.world.WeatherConditions; import com.minelittlepony.unicopia.util.serialization.PacketCodecUtils; @@ -794,7 +795,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp STORM, TALE; - private static final BalloonDesign[] VALUES = values(); + public static final BalloonDesign[] VALUES = values(); public static final EnumCodec CODEC = StringIdentifiable.createCodec(BalloonDesign::values); public static final PacketCodec PACKET_CODEC = PacketCodecUtils.ofEnum(BalloonDesign.class); @@ -806,7 +807,7 @@ public class AirBalloonEntity extends MobEntity implements EntityCollisions.Comp } public static AirBalloonEntity.BalloonDesign of(World world, ItemStack stack) { - AirBalloonEntity.BalloonDesign design = stack.getOrDefault(UDataComponentTypes.BALLOON_DESIGN, NONE); + AirBalloonEntity.BalloonDesign design = BalloonDesignComponent.get(stack).design(); if (design == NONE) { return VALUES[1 + world.getRandom().nextInt(VALUES.length - 1)]; } diff --git a/src/main/java/com/minelittlepony/unicopia/item/GiantBalloonItem.java b/src/main/java/com/minelittlepony/unicopia/item/GiantBalloonItem.java new file mode 100644 index 00000000..80828311 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/GiantBalloonItem.java @@ -0,0 +1,27 @@ +package com.minelittlepony.unicopia.item; + +import java.util.Arrays; +import java.util.List; + +import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity.BalloonDesign; +import com.minelittlepony.unicopia.item.component.BalloonDesignComponent; +import com.minelittlepony.unicopia.item.component.UDataComponentTypes; +import com.minelittlepony.unicopia.item.group.MultiItem; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class GiantBalloonItem extends Item implements MultiItem { + public GiantBalloonItem(Settings settings) { + super(settings); + } + + @Override + public List getDefaultStacks() { + return Arrays.stream(BalloonDesign.VALUES).map(design -> { + ItemStack stack = getDefaultStack(); + stack.set(UDataComponentTypes.BALLOON_DESIGN, new BalloonDesignComponent(design, true)); + return stack; + }).toList(); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItems.java b/src/main/java/com/minelittlepony/unicopia/item/UItems.java index a5761146..474831ed 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/item/UItems.java @@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.block.cloud.CloudBedBlock; import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity; import com.minelittlepony.unicopia.entity.mob.UEntities; import com.minelittlepony.unicopia.item.cloud.CloudBedItem; +import com.minelittlepony.unicopia.item.component.BalloonDesignComponent; import com.minelittlepony.unicopia.item.component.BreaksIntoItemComponent; import com.minelittlepony.unicopia.item.component.UDataComponentTypes; import com.minelittlepony.unicopia.item.enchantment.UEnchantments; @@ -179,7 +180,7 @@ public interface UItems { Item BAMBOO_BASKET = register("bamboo_basket", new BasketItem(AirBalloonEntity.BasketType.of(BoatEntity.Type.BAMBOO), new Item.Settings().maxCount(1)), ItemGroups.TOOLS); Item PALM_BASKET = register("palm_basket", new BasketItem(AirBalloonEntity.BasketType.of(UWoodTypes.PALM_BOAT_TYPE), new Item.Settings().maxCount(1)), ItemGroups.TOOLS); - Item GIANT_BALLOON = register("giant_balloon", new Item(new Item.Settings().maxCount(1).component(UDataComponentTypes.BALLOON_DESIGN, AirBalloonEntity.BalloonDesign.NONE)), ItemGroups.TOOLS); + Item GIANT_BALLOON = register("giant_balloon", new GiantBalloonItem(new Item.Settings().maxCount(1).component(UDataComponentTypes.BALLOON_DESIGN, BalloonDesignComponent.DEFAULT)), ItemGroups.TOOLS); Item SPECTRAL_CLOCK = register("spectral_clock", new Item(new Item.Settings()), ItemGroups.TOOLS); Item WHITE_BED_SHEETS = register(CloudBedBlock.SheetPattern.WHITE); diff --git a/src/main/java/com/minelittlepony/unicopia/item/component/BalloonDesignComponent.java b/src/main/java/com/minelittlepony/unicopia/item/component/BalloonDesignComponent.java new file mode 100644 index 00000000..a189c425 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/item/component/BalloonDesignComponent.java @@ -0,0 +1,46 @@ +package com.minelittlepony.unicopia.item.component; + +import java.util.function.Consumer; + +import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity; +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; + +import io.netty.buffer.ByteBuf; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Item.TooltipContext; +import net.minecraft.item.tooltip.TooltipAppender; +import net.minecraft.item.tooltip.TooltipType; +import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; + +public record BalloonDesignComponent(AirBalloonEntity.BalloonDesign design, boolean showInTooltip) implements TooltipAppender { + public static final BalloonDesignComponent DEFAULT = new BalloonDesignComponent(AirBalloonEntity.BalloonDesign.NONE, false); + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + AirBalloonEntity.BalloonDesign.CODEC.fieldOf("design").forGetter(BalloonDesignComponent::design), + Codec.BOOL.fieldOf("show_in_tooltip").forGetter(BalloonDesignComponent::showInTooltip) + ).apply(instance, BalloonDesignComponent::new)); + public static final PacketCodec PACKET_CODEC = PacketCodec.tuple( + AirBalloonEntity.BalloonDesign.PACKET_CODEC, BalloonDesignComponent::design, + PacketCodecs.BOOL, BalloonDesignComponent::showInTooltip, + BalloonDesignComponent::new + ); + + public static BalloonDesignComponent get(ItemStack stack) { + return stack.getOrDefault(UDataComponentTypes.BALLOON_DESIGN, DEFAULT); + } + + public static ItemStack set(ItemStack stack, BalloonDesignComponent variant) { + stack.set(UDataComponentTypes.BALLOON_DESIGN, variant); + return stack; + } + + @Override + public void appendTooltip(TooltipContext context, Consumer tooltip, TooltipType type) { + if (showInTooltip() && design != AirBalloonEntity.BalloonDesign.NONE) { + tooltip.accept(Text.literal(design().name()).formatted(Formatting.LIGHT_PURPLE)); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/item/component/BufferflyVariantComponent.java b/src/main/java/com/minelittlepony/unicopia/item/component/BufferflyVariantComponent.java index 4de36ce5..91874ed1 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/component/BufferflyVariantComponent.java +++ b/src/main/java/com/minelittlepony/unicopia/item/component/BufferflyVariantComponent.java @@ -28,7 +28,6 @@ public record BufferflyVariantComponent (ButterflyEntity.Variant variant, boolea BufferflyVariantComponent::new ); - public static BufferflyVariantComponent get(ItemStack stack) { return stack.getOrDefault(UDataComponentTypes.BUTTERFLY_VARIANT, DEFAULT); } diff --git a/src/main/java/com/minelittlepony/unicopia/item/component/UDataComponentTypes.java b/src/main/java/com/minelittlepony/unicopia/item/component/UDataComponentTypes.java index 752c0dff..5dd990d1 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/component/UDataComponentTypes.java +++ b/src/main/java/com/minelittlepony/unicopia/item/component/UDataComponentTypes.java @@ -7,7 +7,6 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.container.SpellbookState; import com.minelittlepony.unicopia.diet.DietProfile; -import com.minelittlepony.unicopia.entity.mob.AirBalloonEntity; import com.mojang.serialization.Codec; import net.minecraft.component.ComponentType; @@ -21,7 +20,7 @@ public interface UDataComponentTypes { ComponentType SPELLBOOK_STATE = register("spellbook_state", builder -> builder.codec(SpellbookState.CODEC).packetCodec(SpellbookState.PACKET_CODEC).cache()); ComponentType GLOWING = register("glowing", builder -> builder.codec(Codec.BOOL).packetCodec(PacketCodecs.BOOL)); ComponentType BUTTERFLY_VARIANT = register("butterfly_variant", builder -> builder.codec(BufferflyVariantComponent.CODEC).packetCodec(BufferflyVariantComponent.PACKET_CODEC)); - ComponentType BALLOON_DESIGN = register("balloon_design", builder -> builder.codec(AirBalloonEntity.BalloonDesign.CODEC).packetCodec(AirBalloonEntity.BalloonDesign.PACKET_CODEC)); + ComponentType BALLOON_DESIGN = register("balloon_design", builder -> builder.codec(BalloonDesignComponent.CODEC).packetCodec(BalloonDesignComponent.PACKET_CODEC)); ComponentType ISSUER = register("issuer", builder -> builder.codec(Issuer.CODEC).packetCodec(Issuer.PACKET_CODEC).cache()); ComponentType CHARGES = register("charges", builder -> builder.codec(Charges.CODEC).packetCodec(Charges.PACKET_CODEC)); ComponentType APPEARANCE = register("appearance", builder -> builder.codec(Appearance.CODEC).packetCodec(Appearance.PACKET_CODEC)); diff --git a/src/main/resources/assets/unicopia/textures/item/dawn_giant_balloon.png b/src/main/resources/assets/unicopia/textures/item/dawn_giant_balloon.png new file mode 100644 index 00000000..33e0aacd Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/dawn_giant_balloon.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/equality_giant_balloon.png b/src/main/resources/assets/unicopia/textures/item/equality_giant_balloon.png new file mode 100644 index 00000000..ec103662 Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/equality_giant_balloon.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/luna_giant_balloon.png b/src/main/resources/assets/unicopia/textures/item/luna_giant_balloon.png new file mode 100644 index 00000000..31c7d9ea Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/luna_giant_balloon.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/storm_giant_balloon.png b/src/main/resources/assets/unicopia/textures/item/storm_giant_balloon.png new file mode 100644 index 00000000..9014681b Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/storm_giant_balloon.png differ diff --git a/src/main/resources/assets/unicopia/textures/item/tale_giant_balloon.png b/src/main/resources/assets/unicopia/textures/item/tale_giant_balloon.png new file mode 100644 index 00000000..22797c5e Binary files /dev/null and b/src/main/resources/assets/unicopia/textures/item/tale_giant_balloon.png differ