From 002b33081edd30d8d9c291dde4b5e5232c6f6019 Mon Sep 17 00:00:00 2001 From: Sollace Date: Mon, 19 Dec 2022 00:47:00 +0000 Subject: [PATCH] 1.19.2 -> 1.19.3 (1.20) [part 3] --- .../client/minelittlepony/AmuletGear.java | 17 ++++++----- .../client/minelittlepony/BangleGear.java | 29 ++++++------------- .../minelittlepony/unicopia/item/UItems.java | 1 + .../item/group/ItemGroupRegistry.java | 18 ++++-------- .../item/{ => group}/UItemGroups.java | 13 +++++---- .../unicopia/item/group/package-info.java | 1 - .../unicopia/mixin/MixinBoatEntity.java | 2 +- .../unicopia/mixin/MixinLivingEntity.java | 4 +-- .../mixin/client/MixinWorldRenderer.java | 2 +- .../mixin/trinkets/MixinTrinketItem.java | 5 +++- .../unicopia/util/RegistryUtils.java | 2 +- 11 files changed, 41 insertions(+), 53 deletions(-) rename src/main/java/com/minelittlepony/unicopia/item/{ => group}/UItemGroups.java (72%) delete mode 100644 src/main/java/com/minelittlepony/unicopia/item/group/package-info.java diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/AmuletGear.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/AmuletGear.java index c18def58..fad07825 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/AmuletGear.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/AmuletGear.java @@ -7,12 +7,14 @@ import java.util.UUID; import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.IModel; import com.minelittlepony.api.model.gear.IGear; +import com.minelittlepony.client.model.IPonyModel; import com.minelittlepony.unicopia.client.render.AmuletFeatureRenderer.AmuletModel; import com.minelittlepony.unicopia.item.AmuletItem; import net.minecraft.client.model.Dilation; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; @@ -23,8 +25,6 @@ class AmuletGear extends AmuletModel implements IGear { private final Map textures = new HashMap<>(); - private IModel model; - public AmuletGear() { super(AmuletModel.getData(new Dilation(0.3F)).createModel()); } @@ -45,9 +45,14 @@ class AmuletGear extends AmuletModel implements IGear { } @Override - public void setModelAttributes(IModel model, Entity entity) { - this.model = model; + public & IPonyModel> void transform(M model, MatrixStack matrices) { + BodyPart part = getGearLocation(); + model.transform(part, matrices); + matrices.translate(0, 0.25, 0); + } + @Override + public void pose(IModel model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) { if (model instanceof BipedEntityModel biped) { setAngles((LivingEntity)entity, biped); } @@ -55,10 +60,6 @@ class AmuletGear extends AmuletModel implements IGear { @Override public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha, UUID interpolatorId) { - BangleGear.popAndApply(model, BodyPart.BODY, stack); - - stack.translate(0, 0.25, 0); - render(stack, consumer, light, overlay, red, green, blue, 1); } } diff --git a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BangleGear.java b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BangleGear.java index 7d48ee22..63ec760b 100644 --- a/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BangleGear.java +++ b/src/main/java/com/minelittlepony/unicopia/client/minelittlepony/BangleGear.java @@ -5,6 +5,7 @@ import java.util.UUID; import com.minelittlepony.api.model.BodyPart; import com.minelittlepony.api.model.IModel; import com.minelittlepony.api.model.gear.IGear; +import com.minelittlepony.client.model.IPonyModel; import com.minelittlepony.common.util.Color; import com.minelittlepony.unicopia.client.render.BraceletFeatureRenderer; import com.minelittlepony.unicopia.client.render.BraceletFeatureRenderer.BraceletModel; @@ -16,6 +17,7 @@ import net.minecraft.client.model.Dilation; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.VertexConsumer; import net.minecraft.client.render.entity.model.BipedEntityModel; +import net.minecraft.client.render.entity.model.EntityModel; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.Entity; import net.minecraft.entity.LivingEntity; @@ -31,8 +33,6 @@ class BangleGear implements IGear { private final BraceletModel steveModel; private final BraceletModel alexModel; - private IModel model; - private final Identifier slot; public BangleGear(Identifier slot) { @@ -58,8 +58,13 @@ class BangleGear implements IGear { } @Override - public void setModelAttributes(IModel model, Entity entity) { - this.model = model; + public & IPonyModel> void transform(M model, MatrixStack matrices) { + BodyPart part = getGearLocation(); + model.transform(part, matrices); + } + + @Override + public void pose(IModel model, Entity entity, boolean rainboom, UUID interpolatorId, float move, float swing, float bodySwing, float ticks) { alex = entity instanceof ClientPlayerEntity && ((ClientPlayerEntity)entity).getModel().startsWith("slim"); FriendshipBraceletItem.getWornBangles((LivingEntity)entity, slot).findFirst().ifPresent(bracelet -> { color = ((DyeableItem)bracelet.getItem()).getColor(bracelet); @@ -76,23 +81,7 @@ class BangleGear implements IGear { @Override public void render(MatrixStack stack, VertexConsumer consumer, int light, int overlay, float red, float green, float blue, float alpha, UUID interpolatorId) { - popAndApply(model, BodyPart.LEGS, stack); - BraceletModel m = alex ? alexModel : steveModel; m.render(stack, consumer, glowing ? 0x0F00F0 : light, overlay, Color.r(color), Color.g(color), Color.b(color), 1); } - - /** - * Discards and applies default transformations without body part rotations. - *

- * TODO: this is a workaround to undo the {@code model.getBodyPart(part).rotate(stack)} in GearFeature. - * That's useful for things that render on the head or body, but not so much if you're on the legs or tail, - * since the default implementation falls to body rotation, which we don't want - */ - static void popAndApply(IModel model, BodyPart part, MatrixStack matrices) { - matrices.pop(); - matrices.push(); - // re-apply leg transformation - model.transform(part, matrices); - } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItems.java b/src/main/java/com/minelittlepony/unicopia/item/UItems.java index 8bccb065..99272021 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.UBlocks; import com.minelittlepony.unicopia.entity.UEntities; import com.minelittlepony.unicopia.item.enchantment.UEnchantments; import com.minelittlepony.unicopia.item.group.ItemGroupRegistry; +import com.minelittlepony.unicopia.item.group.UItemGroups; import com.minelittlepony.unicopia.item.toxin.UFoodComponents; import net.minecraft.item.*; diff --git a/src/main/java/com/minelittlepony/unicopia/item/group/ItemGroupRegistry.java b/src/main/java/com/minelittlepony/unicopia/item/group/ItemGroupRegistry.java index e6651005..c75349a6 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/group/ItemGroupRegistry.java +++ b/src/main/java/com/minelittlepony/unicopia/item/group/ItemGroupRegistry.java @@ -1,11 +1,9 @@ package com.minelittlepony.unicopia.item.group; import java.util.*; -import java.util.concurrent.TimeUnit; import java.util.function.Supplier; import java.util.stream.Stream; -import com.google.common.cache.*; import com.minelittlepony.unicopia.UTags; import com.minelittlepony.unicopia.Unicopia; @@ -16,21 +14,15 @@ import net.minecraft.registry.Registries; import net.minecraft.registry.tag.TagKey; public interface ItemGroupRegistry { - LoadingCache> STACK_VARIANCES_CACHE = CacheBuilder.newBuilder() - .expireAfterAccess(30, TimeUnit.SECONDS) - .build(CacheLoader.from(i -> { - if (i instanceof MultiItem m) { - return m.getDefaultStacks(); - } - return ItemGroups.SEARCH.getSearchTabStacks().stream().filter(s -> s.getItem() == i).toList(); - })); + Map> REGISTRY = new HashMap<>(); static List getVariations(Item item) { - return STACK_VARIANCES_CACHE.getUnchecked(item); + if (item instanceof MultiItem) { + return ((MultiItem)item).getDefaultStacks(); + } + return List.of(item.getDefaultStack()); } - Map> REGISTRY = new HashMap<>(); - static T register(T item, ItemGroup group) { REGISTRY.computeIfAbsent(group, g -> new HashSet<>()).add(item); return item; diff --git a/src/main/java/com/minelittlepony/unicopia/item/UItemGroups.java b/src/main/java/com/minelittlepony/unicopia/item/group/UItemGroups.java similarity index 72% rename from src/main/java/com/minelittlepony/unicopia/item/UItemGroups.java rename to src/main/java/com/minelittlepony/unicopia/item/group/UItemGroups.java index 734cf2fe..ce7d898e 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/UItemGroups.java +++ b/src/main/java/com/minelittlepony/unicopia/item/group/UItemGroups.java @@ -1,8 +1,9 @@ -package com.minelittlepony.unicopia.item; +package com.minelittlepony.unicopia.item.group; import java.util.stream.Stream; -import com.minelittlepony.unicopia.item.group.ItemGroupRegistry; +import com.minelittlepony.unicopia.item.ChameleonItem; +import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.toxin.Toxic; import com.minelittlepony.unicopia.item.toxin.ToxicHolder; @@ -11,10 +12,12 @@ import net.minecraft.registry.Registries; public interface UItemGroups { ItemGroup ALL_ITEMS = ItemGroupRegistry.createDynamic("items", UItems.EMPTY_JAR::getDefaultStack, () -> { - return Stream.concat(Stream.of(Items.APPLE), UItems.ITEMS.stream().filter(item -> !(item instanceof ChameleonItem) || ((ChameleonItem)item).isFullyDisguised())); + return Stream.concat(Stream.of(Items.APPLE), UItems.ITEMS.stream() + .filter(item -> !(item instanceof ChameleonItem) || ((ChameleonItem)item).isFullyDisguised())); }); ItemGroup HORSE_FEED = ItemGroupRegistry.createDynamic("horsefeed", UItems.ZAP_APPLE::getDefaultStack, () -> { - return Registries.ITEM.stream().filter(item -> ((ToxicHolder)item).getToxic(item.getDefaultStack()) != Toxic.EMPTY); + return Registries.ITEM.stream() + .filter(item -> ((ToxicHolder)item).getToxic(item.getDefaultStack()) != Toxic.EMPTY); }); ItemGroup EARTH_PONY_ITEMS = ItemGroupRegistry.createGroupFromTag("earth_pony", UItems.APPLE_PIE::getDefaultStack); @@ -24,6 +27,6 @@ public interface UItemGroups { ItemGroup CHANGELING_ITEMS = ItemGroupRegistry.createGroupFromTag("changeling", UItems.LOVE_BOTTLE::getDefaultStack); static void bootstrap() { - UItems.bootstrap(); + ItemGroupRegistry.bootstrap(); } } diff --git a/src/main/java/com/minelittlepony/unicopia/item/group/package-info.java b/src/main/java/com/minelittlepony/unicopia/item/group/package-info.java deleted file mode 100644 index 5e530073..00000000 --- a/src/main/java/com/minelittlepony/unicopia/item/group/package-info.java +++ /dev/null @@ -1 +0,0 @@ -package com.minelittlepony.unicopia.item.group; \ No newline at end of file diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinBoatEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinBoatEntity.java index fdc0fff1..c1880bd5 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinBoatEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinBoatEntity.java @@ -31,7 +31,7 @@ abstract class MixinBoatEntity extends Entity implements LavaAffine { "fall", "canAddPassenger" }, - at = @At(value = "FIELD", target = "net/minecraft/tag/FluidTags.WATER:Lnet/minecraft/tag/TagKey;", opcode = Opcodes.GETSTATIC) + at = @At(value = "FIELD", target = "net/minecraft/tag/FluidTags.WATER:Lnet/minecraft/registry/tag/TagKey;", opcode = Opcodes.GETSTATIC) ) private TagKey redirectFluidTag() { return isLavaAffine() ? FluidTags.LAVA : FluidTags.WATER; diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java b/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java index c6df6a4d..b4f6e4f5 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/MixinLivingEntity.java @@ -2,8 +2,7 @@ package com.minelittlepony.unicopia.mixin; import java.util.Optional; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.*; import org.spongepowered.asm.mixin.gen.Accessor; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Constant; @@ -133,6 +132,7 @@ abstract class MixinLivingEntity extends Entity implements LivingEntityDuck { get().tick(); } + @Dynamic("Compiler-generated class-init() method") @Inject(method = "()V", at = @At("RETURN"), remap = false) private static void clinit(CallbackInfo info) { Creature.boostrap(); diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinWorldRenderer.java b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinWorldRenderer.java index 313a4488..be7a997b 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinWorldRenderer.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/client/MixinWorldRenderer.java @@ -41,7 +41,7 @@ abstract class MixinWorldRenderer implements SynchronousResourceReloader, AutoCl + "Lnet/minecraft/client/render/Camera;" + "Lnet/minecraft/client/render/GameRenderer;" + "Lnet/minecraft/client/render/LightmapTextureManager;" - + "Lnet/minecraft/util/math/Matrix4f;" + + "Lorg/joml/Matrix4f;" + ")V", at = @At(value = "FIELD", target = "Lnet/minecraft/client/render/WorldRenderer;blockBreakingProgressions:Lit/unimi/dsi/fastutil/longs/Long2ObjectMap;") ) diff --git a/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinTrinketItem.java b/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinTrinketItem.java index eefd329f..38fae733 100644 --- a/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinTrinketItem.java +++ b/src/main/java/com/minelittlepony/unicopia/mixin/trinkets/MixinTrinketItem.java @@ -9,7 +9,10 @@ import net.minecraft.item.ItemStack; @Mixin(TrinketItem.class) abstract class MixinTrinketItem { - // overwrite with a max-count aware version (fixes inserting) + /** + * @reason Overwrite with a max-count aware version (fixes inserting) + * @author _ + */ @Overwrite public static boolean equipItem(PlayerEntity user, ItemStack stack) { return TrinketsDelegateImpl.INSTANCE.getInventories(user) diff --git a/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java b/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java index 0ddf531e..d2619e91 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/util/RegistryUtils.java @@ -18,7 +18,7 @@ public interface RegistryUtils { } static Registry createDefaulted(Identifier id, String def) { - return FabricRegistryBuilder.from(new SimpleDefaultedRegistry(def, RegistryKey.ofRegistry(id), Lifecycle.stable(), true)).buildAndRegister(); + return FabricRegistryBuilder.from(new SimpleDefaultedRegistry(def, RegistryKey.ofRegistry(id), Lifecycle.stable(), false)).buildAndRegister(); } static RegistryEntryList entriesForTag(World world, TagKey key) {