From d8ec424fa0350d6de00b03bff8a61f789f58c3fc Mon Sep 17 00:00:00 2001 From: PepperCode1 <44146161+PepperCode1@users.noreply.github.com> Date: Sun, 11 Dec 2022 15:23:15 -0800 Subject: [PATCH] Post-PR changes - Rename ILangParial to LangPartial - Simplify LangPartial and remove default LangMerger constructor - Create CustomArmPoseItem and de-hardcode PotatoCannonItem and ZapperItem - Fix mixin order - Update Flywheel --- gradle.properties | 2 +- src/main/java/com/simibubi/create/Create.java | 3 +- .../curiosities/weapons/PotatoCannonItem.java | 16 +++++++++- .../curiosities/zapper/ZapperItem.java | 16 +++++++++- .../source/StatTrackingDisplaySource.java | 5 +-- .../foundation/data/AllLangPartials.java | 29 ++++++++--------- .../create/foundation/data/ILangPartial.java | 27 ---------------- .../create/foundation/data/LangMerger.java | 21 +++++-------- .../create/foundation/data/LangPartial.java | 18 +++++++++++ .../foundation/item/CustomArmPoseItem.java | 13 ++++++++ .../mixin/PlayerEntityRendererMixin.java | 31 ------------------- .../foundation/mixin/PlayerRendererMixin.java | 28 +++++++++++++++++ src/main/resources/create.mixins.json | 2 +- 13 files changed, 117 insertions(+), 94 deletions(-) delete mode 100644 src/main/java/com/simibubi/create/foundation/data/ILangPartial.java create mode 100644 src/main/java/com/simibubi/create/foundation/data/LangPartial.java create mode 100644 src/main/java/com/simibubi/create/foundation/item/CustomArmPoseItem.java delete mode 100644 src/main/java/com/simibubi/create/foundation/mixin/PlayerEntityRendererMixin.java create mode 100644 src/main/java/com/simibubi/create/foundation/mixin/PlayerRendererMixin.java diff --git a/gradle.properties b/gradle.properties index 04131e4ce..2bb5c89ec 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,7 +21,7 @@ parchment_version = 2022.11.06 # dependency versions registrate_version = MC1.18.2-1.1.3 flywheel_minecraft_version = 1.18.2 -flywheel_version = 0.6.8-96 +flywheel_version = 0.6.8-97 jei_minecraft_version = 1.18.2 jei_version = 9.7.0.209 curios_minecraft_version = 1.18.2 diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index 7271422ff..63ef30398 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -29,6 +29,7 @@ import com.simibubi.create.foundation.block.CopperRegistries; import com.simibubi.create.foundation.command.ServerLagger; import com.simibubi.create.foundation.config.AllConfigs; import com.simibubi.create.foundation.config.ContraptionMovementSetting; +import com.simibubi.create.foundation.data.AllLangPartials; import com.simibubi.create.foundation.data.CreateRegistrate; import com.simibubi.create.foundation.data.LangMerger; import com.simibubi.create.foundation.data.TagGen; @@ -161,7 +162,7 @@ public class Create { TagGen.datagen(); DataGenerator gen = event.getGenerator(); if (event.includeClient()) { - gen.addProvider(new LangMerger(gen)); + gen.addProvider(new LangMerger(gen, ID, "Create", AllLangPartials.values())); gen.addProvider(AllSoundEvents.provider(gen)); } if (event.includeServer()) { diff --git a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonItem.java b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonItem.java index 7b132d8d0..50df0524b 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/weapons/PotatoCannonItem.java @@ -5,6 +5,8 @@ import java.util.Optional; import java.util.function.Consumer; import java.util.function.Predicate; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.AllEnchantments; import com.simibubi.create.AllEntityTypes; import com.simibubi.create.Create; @@ -12,6 +14,7 @@ import com.simibubi.create.CreateClient; import com.simibubi.create.content.curiosities.armor.BackTankUtil; import com.simibubi.create.content.curiosities.zapper.ShootableGadgetItemMethods; import com.simibubi.create.foundation.config.AllConfigs; +import com.simibubi.create.foundation.item.CustomArmPoseItem; import com.simibubi.create.foundation.item.render.SimpleCustomRenderer; import com.simibubi.create.foundation.utility.AnimationTickHolder; import com.simibubi.create.foundation.utility.Components; @@ -20,6 +23,8 @@ import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; +import net.minecraft.client.model.HumanoidModel.ArmPose; +import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.client.player.LocalPlayer; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction.Axis; @@ -46,7 +51,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.IItemRenderProperties; -public class PotatoCannonItem extends ProjectileWeaponItem { +public class PotatoCannonItem extends ProjectileWeaponItem implements CustomArmPoseItem { public static ItemStack CLIENT_CURRENT_AMMO = ItemStack.EMPTY; public static final int MAX_DAMAGE = 100; @@ -270,6 +275,15 @@ public class PotatoCannonItem extends ProjectileWeaponItem { return UseAnim.NONE; } + @Override + @Nullable + public ArmPose getArmPose(ItemStack stack, AbstractClientPlayer player, InteractionHand hand) { + if (!player.swinging) { + return ArmPose.CROSSBOW_HOLD; + } + return null; + } + @Override public int getDefaultProjectileRange() { return 15; diff --git a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java index 43ddf5fe4..f0b7b85ff 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java +++ b/src/main/java/com/simibubi/create/content/curiosities/zapper/ZapperItem.java @@ -4,9 +4,12 @@ import java.util.List; import javax.annotation.Nonnull; +import org.jetbrains.annotations.Nullable; + import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllTags.AllBlockTags; import com.simibubi.create.CreateClient; +import com.simibubi.create.foundation.item.CustomArmPoseItem; import com.simibubi.create.foundation.item.ItemDescription; import com.simibubi.create.foundation.utility.BlockHelper; import com.simibubi.create.foundation.utility.Lang; @@ -14,6 +17,8 @@ import com.simibubi.create.foundation.utility.NBTHelper; import com.simibubi.create.foundation.utility.NBTProcessors; import net.minecraft.ChatFormatting; +import net.minecraft.client.model.HumanoidModel.ArmPose; +import net.minecraft.client.player.AbstractClientPlayer; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.NbtUtils; @@ -43,7 +48,7 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.DistExecutor; -public abstract class ZapperItem extends Item { +public abstract class ZapperItem extends Item implements CustomArmPoseItem { public ZapperItem(Properties properties) { super(properties.stacksTo(1)); @@ -213,6 +218,15 @@ public abstract class ZapperItem extends Item { return UseAnim.NONE; } + @Override + @Nullable + public ArmPose getArmPose(ItemStack stack, AbstractClientPlayer player, InteractionHand hand) { + if (!player.swinging) { + return ArmPose.CROSSBOW_HOLD; + } + return null; + } + public static void configureSettings(ItemStack stack, PlacementPatterns pattern) { CompoundTag nbt = stack.getOrCreateTag(); NBTHelper.writeEnum(nbt, "Pattern", pattern); diff --git a/src/main/java/com/simibubi/create/content/logistics/block/display/source/StatTrackingDisplaySource.java b/src/main/java/com/simibubi/create/content/logistics/block/display/source/StatTrackingDisplaySource.java index 319c63e43..9d6b9f3f5 100644 --- a/src/main/java/com/simibubi/create/content/logistics/block/display/source/StatTrackingDisplaySource.java +++ b/src/main/java/com/simibubi/create/content/logistics/block/display/source/StatTrackingDisplaySource.java @@ -1,8 +1,11 @@ package com.simibubi.create.content.logistics.block.display.source; +import java.util.stream.Stream; + import com.simibubi.create.content.logistics.block.display.DisplayLinkContext; import com.simibubi.create.foundation.gui.ModularGuiLineBuilder; import com.simibubi.create.foundation.utility.IntAttached; + import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.server.level.ServerLevel; @@ -15,8 +18,6 @@ import net.minecraft.world.scores.criteria.ObjectiveCriteria.RenderType; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -import java.util.stream.Stream; - public abstract class StatTrackingDisplaySource extends ScoreboardDisplaySource { @Override diff --git a/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java b/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java index 9e8e1fba0..ff55e5a45 100644 --- a/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java +++ b/src/main/java/com/simibubi/create/foundation/data/AllLangPartials.java @@ -3,11 +3,12 @@ package com.simibubi.create.foundation.data; import com.google.common.base.Supplier; import com.google.gson.JsonElement; import com.simibubi.create.AllSoundEvents; +import com.simibubi.create.Create; import com.simibubi.create.foundation.advancement.AllAdvancements; import com.simibubi.create.foundation.ponder.PonderLocalization; import com.simibubi.create.foundation.utility.Lang; -public enum AllLangPartials implements ILangPartial { +public enum AllLangPartials implements LangPartial { ADVANCEMENTS("Advancements", AllAdvancements::provideLangEntries), INTERFACE("UI & Messages"), @@ -17,27 +18,23 @@ public enum AllLangPartials implements ILangPartial { ; - private String display; - private Supplier provider; + private final String displayName; + private final Supplier provider; - private AllLangPartials(String display) { - this.display = display; - this.provider = getDefault(); + private AllLangPartials(String displayName) { + this.displayName = displayName; + String fileName = Lang.asId(name()); + this.provider = () -> LangPartial.fromResource(Create.ID, fileName); } - private AllLangPartials(String display, Supplier customProvider) { - this.display = display; - this.provider = customProvider; + private AllLangPartials(String displayName, Supplier provider) { + this.displayName = displayName; + this.provider = provider; } @Override - public String getDisplay() { - return display; - } - - @Override - public String getFileName() { - return Lang.asId(name()); + public String getDisplayName() { + return displayName; } @Override diff --git a/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java b/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java deleted file mode 100644 index 0bbf4dd6a..000000000 --- a/src/main/java/com/simibubi/create/foundation/data/ILangPartial.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.simibubi.create.foundation.data; - -import com.google.common.base.Supplier; -import com.google.gson.JsonElement; -import com.simibubi.create.Create; -import com.simibubi.create.foundation.utility.FilesHelper; - -public interface ILangPartial { - - String getDisplay(); - String getFileName(); - - default String getModID() { return Create.ID; } - - JsonElement provide(); - - private JsonElement fromResource() { - String fileName = getFileName(); - String filepath = "assets/" + getModID() + "/lang/default/" + fileName + ".json"; - JsonElement element = FilesHelper.loadJsonResource(filepath); - if (element == null) - throw new IllegalStateException(String.format("Could not find default lang file: %s", filepath)); - return element; - } - - default Supplier getDefault() { return this::fromResource; } -} diff --git a/src/main/java/com/simibubi/create/foundation/data/LangMerger.java b/src/main/java/com/simibubi/create/foundation/data/LangMerger.java index 90fd5d109..7c26f8d8a 100644 --- a/src/main/java/com/simibubi/create/foundation/data/LangMerger.java +++ b/src/main/java/com/simibubi/create/foundation/data/LangMerger.java @@ -33,15 +33,15 @@ import net.minecraft.util.GsonHelper; public class LangMerger implements DataProvider { - private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting() + private static final Gson GSON = new GsonBuilder().setPrettyPrinting() .disableHtmlEscaping() .create(); - static final String CATEGORY_HEADER = "\t\"_\": \"->------------------------] %s [------------------------<-\","; + private static final String CATEGORY_HEADER = "\t\"_\": \"->------------------------] %s [------------------------<-\","; private DataGenerator gen; private final String modid; private final String displayName; - private final ILangPartial[] langPartials; + private final LangPartial[] langPartials; private List mergedLangData; private Map> populatedLangData; @@ -50,11 +50,7 @@ public class LangMerger implements DataProvider { private List langIgnore; - public LangMerger(DataGenerator gen) { - this(gen, Create.ID, "Create", AllLangPartials.values()); - } - - public LangMerger(DataGenerator gen, String modid, String displayName, T[] langPartials) { + public LangMerger(DataGenerator gen, String modid, String displayName, T[] langPartials) { this.gen = gen; this.modid = modid; this.displayName = displayName; @@ -67,7 +63,7 @@ public class LangMerger implements DataProvider { populateLangIgnore(); } - private void populateLangIgnore() { + protected void populateLangIgnore() { // Key prefixes added here will NOT be transferred to lang templates langIgnore.add("create.ponder.debug_"); // Ponder debug scene text langIgnore.add("create.gui.chromatic_projector"); @@ -82,7 +78,7 @@ public class LangMerger implements DataProvider { @Override public String getName() { - return "Lang merger"; + return displayName + "'s lang merger"; } @Override @@ -229,8 +225,8 @@ public class LangMerger implements DataProvider { } private void collectEntries() { - for (ILangPartial partial : langPartials) - addAll(partial.getDisplay(), partial.provide() + for (LangPartial partial : langPartials) + addAll(partial.getDisplayName(), partial.provide() .getAsJsonObject()); } @@ -247,7 +243,6 @@ public class LangMerger implements DataProvider { try (BufferedWriter bufferedwriter = Files.newBufferedWriter(target)) { Create.LOGGER.info(message); bufferedwriter.write(data); - bufferedwriter.close(); } } diff --git a/src/main/java/com/simibubi/create/foundation/data/LangPartial.java b/src/main/java/com/simibubi/create/foundation/data/LangPartial.java new file mode 100644 index 000000000..a81807588 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/data/LangPartial.java @@ -0,0 +1,18 @@ +package com.simibubi.create.foundation.data; + +import com.google.gson.JsonElement; +import com.simibubi.create.foundation.utility.FilesHelper; + +public interface LangPartial { + String getDisplayName(); + + JsonElement provide(); + + static JsonElement fromResource(String namespace, String fileName) { + String path = "assets/" + namespace + "/lang/default/" + fileName + ".json"; + JsonElement element = FilesHelper.loadJsonResource(path); + if (element == null) + throw new IllegalStateException(String.format("Could not find default lang file: %s", path)); + return element; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/item/CustomArmPoseItem.java b/src/main/java/com/simibubi/create/foundation/item/CustomArmPoseItem.java new file mode 100644 index 000000000..fbf092e4e --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/item/CustomArmPoseItem.java @@ -0,0 +1,13 @@ +package com.simibubi.create.foundation.item; + +import org.jetbrains.annotations.Nullable; + +import net.minecraft.client.model.HumanoidModel.ArmPose; +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.item.ItemStack; + +public interface CustomArmPoseItem { + @Nullable + ArmPose getArmPose(ItemStack stack, AbstractClientPlayer player, InteractionHand hand); +} diff --git a/src/main/java/com/simibubi/create/foundation/mixin/PlayerEntityRendererMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/PlayerEntityRendererMixin.java deleted file mode 100644 index f3ceebfca..000000000 --- a/src/main/java/com/simibubi/create/foundation/mixin/PlayerEntityRendererMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.simibubi.create.foundation.mixin; - -import com.simibubi.create.content.curiosities.zapper.ZapperItem; - -import net.minecraft.world.item.Item; - -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import com.simibubi.create.content.curiosities.weapons.PotatoCannonItem; -import net.minecraft.client.model.HumanoidModel; -import net.minecraft.client.player.AbstractClientPlayer; -import net.minecraft.client.renderer.entity.player.PlayerRenderer; -import net.minecraft.world.InteractionHand; - -@Mixin(PlayerRenderer.class) -public class PlayerEntityRendererMixin { - @Inject( - method = "getArmPose", - at = @At("HEAD"), - cancellable = true - ) - private static void getArmPose(AbstractClientPlayer player, InteractionHand hand, CallbackInfoReturnable ci) { - Item handItem = player.getItemInHand(hand).getItem(); - if (!player.swinging && (handItem instanceof PotatoCannonItem || handItem instanceof ZapperItem)) - ci.setReturnValue(HumanoidModel.ArmPose.CROSSBOW_HOLD); - } -} - diff --git a/src/main/java/com/simibubi/create/foundation/mixin/PlayerRendererMixin.java b/src/main/java/com/simibubi/create/foundation/mixin/PlayerRendererMixin.java new file mode 100644 index 000000000..50c7dd23d --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/mixin/PlayerRendererMixin.java @@ -0,0 +1,28 @@ +package com.simibubi.create.foundation.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import com.simibubi.create.foundation.item.CustomArmPoseItem; + +import net.minecraft.client.model.HumanoidModel.ArmPose; +import net.minecraft.client.player.AbstractClientPlayer; +import net.minecraft.client.renderer.entity.player.PlayerRenderer; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.item.ItemStack; + +@Mixin(PlayerRenderer.class) +public class PlayerRendererMixin { + @Inject(method = "getArmPose(Lnet/minecraft/client/player/AbstractClientPlayer;Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/client/model/HumanoidModel$ArmPose;", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/client/player/AbstractClientPlayer;getItemInHand(Lnet/minecraft/world/InteractionHand;)Lnet/minecraft/world/item/ItemStack;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + private static void onGetArmPose(AbstractClientPlayer player, InteractionHand hand, CallbackInfoReturnable cir, ItemStack stack) { + if (stack.getItem() instanceof CustomArmPoseItem armPoseProvider) { + ArmPose pose = armPoseProvider.getArmPose(stack, player, hand); + if (pose != null) { + cir.setReturnValue(pose); + } + } + } +} diff --git a/src/main/resources/create.mixins.json b/src/main/resources/create.mixins.json index 89ebb960b..af3452d15 100644 --- a/src/main/resources/create.mixins.json +++ b/src/main/resources/create.mixins.json @@ -24,8 +24,8 @@ "HeavyBootsOnPlayerMixin", "LevelRendererMixin", "MapRendererMapInstanceMixin", - "PlayerEntityRendererMixin", "ModelDataRefreshMixin", + "PlayerRendererMixin", "WindowResizeMixin", "accessor.AgeableListModelAccessor", "accessor.GameRendererAccessor",