mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 16:28:00 +01:00
Balloons now change their appearance to reflect their type
This commit is contained in:
parent
3d18dedb0c
commit
2723fbf7b3
15 changed files with 95 additions and 8 deletions
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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", "" };
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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<BalloonDesign> CODEC = StringIdentifiable.createCodec(BalloonDesign::values);
|
||||
public static final PacketCodec<ByteBuf, BalloonDesign> 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)];
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<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));
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 6.6 KiB |
Loading…
Reference in a new issue