Skip to content

Commit

Permalink
Balloons now change their appearance to reflect their type
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Oct 12, 2024
1 parent 3d18ded commit 7f43ce1
Show file tree
Hide file tree
Showing 15 changed files with 95 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void getTooltip(ItemStack stack, Item.TooltipContext context, @Nullable P
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
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;
Expand Down Expand Up @@ -132,6 +134,7 @@ static void bootstrap() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand Down Expand Up @@ -64,6 +65,15 @@ static void registerButterfly(ItemModelGenerator itemModelGenerator, Item item)
}).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, 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", "" };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void generateItemModels(ItemModelGenerator itemModelGenerator) {
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,
Expand Down Expand Up @@ -131,8 +131,8 @@ public void generateItemModels(ItemModelGenerator itemModelGenerator) {
.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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
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;
Expand Down Expand Up @@ -794,7 +795,7 @@ public enum BalloonDesign implements StringIdentifiable {
STORM,
TALE;

private static final BalloonDesign[] VALUES = values();
public static final BalloonDesign[] VALUES = values();
public static final EnumCodec<BalloonDesign> CODEC = StringIdentifiable.createCodec(BalloonDesign::values);
public static final PacketCodec<ByteBuf, BalloonDesign> PACKET_CODEC = PacketCodecUtils.ofEnum(BalloonDesign.class);

Expand All @@ -806,7 +807,7 @@ public String asString() {
}

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)];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ItemStack> getDefaultStacks() {
return Arrays.stream(BalloonDesign.VALUES).map(design -> {
ItemStack stack = getDefaultStack();
stack.set(UDataComponentTypes.BALLOON_DESIGN, new BalloonDesignComponent(design, true));
return stack;
}).toList();
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/minelittlepony/unicopia/item/UItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<BalloonDesignComponent> 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<ByteBuf, BalloonDesignComponent> 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<Text> tooltip, TooltipType type) {
if (showInTooltip() && design != AirBalloonEntity.BalloonDesign.NONE) {
tooltip.accept(Text.literal(design().name()).formatted(Formatting.LIGHT_PURPLE));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
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;
Expand All @@ -21,7 +20,7 @@ public interface UDataComponentTypes {
ComponentType<SpellbookState> SPELLBOOK_STATE = register("spellbook_state", builder -> builder.codec(SpellbookState.CODEC).packetCodec(SpellbookState.PACKET_CODEC).cache());
ComponentType<Boolean> GLOWING = register("glowing", builder -> builder.codec(Codec.BOOL).packetCodec(PacketCodecs.BOOL));
ComponentType<BufferflyVariantComponent> BUTTERFLY_VARIANT = register("butterfly_variant", builder -> builder.codec(BufferflyVariantComponent.CODEC).packetCodec(BufferflyVariantComponent.PACKET_CODEC));
ComponentType<AirBalloonEntity.BalloonDesign> BALLOON_DESIGN = register("balloon_design", builder -> builder.codec(AirBalloonEntity.BalloonDesign.CODEC).packetCodec(AirBalloonEntity.BalloonDesign.PACKET_CODEC));
ComponentType<BalloonDesignComponent> BALLOON_DESIGN = register("balloon_design", builder -> builder.codec(BalloonDesignComponent.CODEC).packetCodec(BalloonDesignComponent.PACKET_CODEC));
ComponentType<Issuer> ISSUER = register("issuer", builder -> builder.codec(Issuer.CODEC).packetCodec(Issuer.PACKET_CODEC).cache());
ComponentType<Charges> CHARGES = register("charges", builder -> builder.codec(Charges.CODEC).packetCodec(Charges.PACKET_CODEC));
ComponentType<Appearance> APPEARANCE = register("appearance", builder -> builder.codec(Appearance.CODEC).packetCodec(Appearance.PACKET_CODEC));
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7f43ce1

Please sign in to comment.