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
This commit is contained in:
PepperCode1 2022-12-11 15:23:15 -08:00
parent d6e8ac73df
commit d8ec424fa0
13 changed files with 117 additions and 94 deletions

View file

@ -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

View file

@ -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()) {

View file

@ -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;

View file

@ -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);

View file

@ -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

View file

@ -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<JsonElement> provider;
private final String displayName;
private final Supplier<JsonElement> 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<JsonElement> customProvider) {
this.display = display;
this.provider = customProvider;
private AllLangPartials(String displayName, Supplier<JsonElement> 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

View file

@ -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<JsonElement> getDefault() { return this::fromResource; }
}

View file

@ -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<Object> mergedLangData;
private Map<String, List<Object>> populatedLangData;
@ -50,11 +50,7 @@ public class LangMerger implements DataProvider {
private List<String> langIgnore;
public LangMerger(DataGenerator gen) {
this(gen, Create.ID, "Create", AllLangPartials.values());
}
public <T extends ILangPartial> LangMerger(DataGenerator gen, String modid, String displayName, T[] langPartials) {
public <T extends LangPartial> 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();
}
}

View file

@ -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;
}
}

View file

@ -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);
}

View file

@ -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<HumanoidModel.ArmPose> ci) {
Item handItem = player.getItemInHand(hand).getItem();
if (!player.swinging && (handItem instanceof PotatoCannonItem || handItem instanceof ZapperItem))
ci.setReturnValue(HumanoidModel.ArmPose.CROSSBOW_HOLD);
}
}

View file

@ -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<ArmPose> cir, ItemStack stack) {
if (stack.getItem() instanceof CustomArmPoseItem armPoseProvider) {
ArmPose pose = armPoseProvider.getArmPose(stack, player, hand);
if (pose != null) {
cir.setReturnValue(pose);
}
}
}
}

View file

@ -24,8 +24,8 @@
"HeavyBootsOnPlayerMixin",
"LevelRendererMixin",
"MapRendererMapInstanceMixin",
"PlayerEntityRendererMixin",
"ModelDataRefreshMixin",
"PlayerRendererMixin",
"WindowResizeMixin",
"accessor.AgeableListModelAccessor",
"accessor.GameRendererAccessor",