From c27e2a5ed0713b3ab1b3c882d2d22e5e63010087 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Sun, 3 Aug 2025 16:27:16 +0300 Subject: [PATCH 01/17] implement data components for MOST new nbt uses --- .../api/gui/widget/FloatInputWidget.java | 88 +++++ .../api/placeholder/MultiLineComponent.java | 73 ++--- .../api/placeholder/PlaceholderUtils.java | 5 +- .../common/cover/ComputerMonitorCover.java | 61 ++-- .../cover/WirelessTransmitterCover.java | 4 +- .../item/datacomponents/BindingData.java | 62 ++++ .../datacomponents/ComputerMonitorConfig.java | 49 +++ .../item/datacomponents/FormatStringList.java | 69 ++++ .../item/datacomponents/TextLineList.java | 39 +++ .../gtceu/data/item/GTDataComponents.java | 36 +- .../placeholder}/GTPlaceholders.java | 308 ++++++++++-------- .../gtceu/forge/CommonEventListener.java | 16 + 12 files changed, 582 insertions(+), 228 deletions(-) create mode 100644 src/main/java/com/gregtechceu/gtceu/api/gui/widget/FloatInputWidget.java create mode 100644 src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/BindingData.java create mode 100644 src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/ComputerMonitorConfig.java create mode 100644 src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/FormatStringList.java create mode 100644 src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/TextLineList.java rename src/main/java/com/gregtechceu/gtceu/{common/data => data/placeholder}/GTPlaceholders.java (73%) diff --git a/src/main/java/com/gregtechceu/gtceu/api/gui/widget/FloatInputWidget.java b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/FloatInputWidget.java new file mode 100644 index 00000000000..3a5d6dd178e --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/gui/widget/FloatInputWidget.java @@ -0,0 +1,88 @@ +package com.gregtechceu.gtceu.api.gui.widget; + +import com.lowdragmc.lowdraglib.gui.widget.TextFieldWidget; +import com.lowdragmc.lowdraglib.utils.Position; +import com.lowdragmc.lowdraglib.utils.Size; + +import net.minecraft.util.Mth; + +import java.util.function.Consumer; +import java.util.function.Supplier; + +/** + * A widget containing a floating point input field, as well as adjacent buttons for increasing or decreasing the value. + * + *

+ * The buttons' change amount can be altered with Ctrl, Shift, or both.
+ * The input is limited by a minimum and maximum value. + *

+ */ +public class FloatInputWidget extends NumberInputWidget { + + public FloatInputWidget(Supplier valueSupplier, Consumer onChanged) { + super(valueSupplier, onChanged); + } + + public FloatInputWidget(Position position, Supplier valueSupplier, Consumer onChanged) { + super(position, valueSupplier, onChanged); + } + + public FloatInputWidget(Position position, Size size, Supplier valueSupplier, Consumer onChanged) { + super(position, size, valueSupplier, onChanged); + } + + public FloatInputWidget(int x, int y, int width, int height, Supplier valueSupplier, + Consumer onChanged) { + super(x, y, width, height, valueSupplier, onChanged); + } + + @Override + protected Float defaultMin() { + return 0.0f; + } + + @Override + protected Float defaultMax() { + return Float.MAX_VALUE; + } + + @Override + protected String toText(Float value) { + return String.valueOf(value); + } + + @Override + protected Float fromText(String value) { + return Float.parseFloat(value); + } + + @Override + protected ChangeValues getChangeValues() { + return new ChangeValues<>(1.0f, 0.1f, 0.01f, 0.001f); + } + + @Override + protected Float add(Float a, Float b) { + return a + b; + } + + @Override + protected Float multiply(Float a, Float b) { + return a * b; + } + + @Override + protected Float clamp(Float value, Float min, Float max) { + return Mth.clamp(value, min, max); + } + + @Override + protected void setTextFieldRange(TextFieldWidget textField, Float min, Float max) { + textField.setNumbersOnly(min, max); + } + + @Override + protected Float getOne(boolean positive) { + return positive ? 1.0f : -1.0f; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java b/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java index dcaacaa61e4..c4a9d7bb5d6 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java +++ b/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java @@ -1,24 +1,36 @@ package com.gregtechceu.gtceu.api.placeholder; -import com.gregtechceu.gtceu.utils.GTUtil; - import net.minecraft.ChatFormatting; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.*; +import com.mojang.serialization.Codec; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.UnmodifiableView; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; public class MultiLineComponent extends ArrayList { + public static final Codec CODEC = ComponentSerialization.CODEC.listOf() + .xmap(list -> { + if (((List) list) instanceof MultiLineComponent multiLine) { + return multiLine; + } + MultiLineComponent multiLine = new MultiLineComponent(); + for (Component c : list) { + multiLine.add(c.copy()); + } + return multiLine; + }, MultiLineComponent::toImmutable); + + public MultiLineComponent() {} + public MultiLineComponent(List components) { - super(); - this.addAll(components); + super(components); } public static MultiLineComponent of(Component c) { @@ -75,8 +87,9 @@ public int toInt() { } public void append(@Nullable String s) { - if (s != null) - GTUtil.getLast(this).append(s); + if (s != null) { + this.getLast().append(s); + } } public void append(char c) { @@ -87,15 +100,20 @@ public MultiLineComponent append(@Nullable List lines) { if (lines == null) return this; if (lines.isEmpty()) return this; for (Component line : lines) { - GTUtil.getLast(this).append(line); - this.add(MutableComponent.create(ComponentContents.EMPTY)); + this.getLast().append(line); + this.add(Component.empty()); } - this.remove(this.size() - 1); + this.removeLast(); + return this; + } + + public MultiLineComponent append(@NotNull Component line) { + this.getLast().append(line); return this; } public void appendNewline() { - this.add(MutableComponent.create(ComponentContents.EMPTY)); + this.add(Component.empty()); } public MultiLineComponent withStyle(Style style) { @@ -110,36 +128,13 @@ public MultiLineComponent withStyle(Style style) { public MultiLineComponent withStyle(ChatFormatting... style) { MultiLineComponent out = MultiLineComponent.empty(); for (MutableComponent c : this) { - out.append(MultiLineComponent.of(c.withStyle(style))); + out.append(c.withStyle(style)); out.appendNewline(); } return out; } - public List toImmutable() { - return new ArrayList<>(this); - } - - public Tag toTag() { - ListTag tag = new ListTag(); - for (MutableComponent component : this) { - tag.add(StringTag.valueOf(Component.Serializer.toJson(component))); - } - return tag; - } - - public static MultiLineComponent fromTag(ListTag tag) { - MultiLineComponent out = MultiLineComponent.empty(); - out.clear(); - for (Tag i : tag) { - out.add(Component.Serializer.fromJson(i.getAsString())); - } - return out; - } - - public long toLong() { - if (this.isEmpty()) return 0; - if (this.size() > 1) throw new NumberFormatException(this.toString()); - return Long.parseLong(this.get(0).getString()); + public @UnmodifiableView List toImmutable() { + return Collections.unmodifiableList(this); } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/placeholder/PlaceholderUtils.java b/src/main/java/com/gregtechceu/gtceu/api/placeholder/PlaceholderUtils.java index eeb8f00cff3..f3967260dda 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/placeholder/PlaceholderUtils.java +++ b/src/main/java/com/gregtechceu/gtceu/api/placeholder/PlaceholderUtils.java @@ -40,8 +40,11 @@ public static void checkArgs(List args, int args_num, } public static long toLong(MultiLineComponent component) throws InvalidNumberException { + if (component.isEmpty()) return 0L; + if (component.size() > 1) throw new InvalidNumberException(component.toString()); + try { - return component.toLong(); + return Long.parseLong(component.getFirst().getString()); } catch (NumberFormatException e) { throw new InvalidNumberException(component.toString()); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/ComputerMonitorCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/ComputerMonitorCover.java index 23b38c2f1fc..6cd066adcb1 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/ComputerMonitorCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/ComputerMonitorCover.java @@ -15,7 +15,9 @@ import com.gregtechceu.gtceu.api.transfer.item.CustomItemStackHandler; import com.gregtechceu.gtceu.client.renderer.cover.CoverTextRenderer; import com.gregtechceu.gtceu.client.renderer.cover.IDynamicCoverRenderer; -import com.gregtechceu.gtceu.data.lang.LangHandler; +import com.gregtechceu.gtceu.common.item.datacomponents.ComputerMonitorConfig; +import com.gregtechceu.gtceu.data.datagen.lang.LangHandler; +import com.gregtechceu.gtceu.data.item.GTDataComponents; import com.gregtechceu.gtceu.integration.create.GTCreateIntegration; import com.gregtechceu.gtceu.utils.GTStringUtils; import com.gregtechceu.gtceu.utils.GTUtil; @@ -28,12 +30,7 @@ import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.Direction; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -42,6 +39,7 @@ import lombok.Getter; import lombok.Setter; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.function.Supplier; @@ -56,7 +54,7 @@ public class ComputerMonitorCover extends CoverBehavior public static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(ComputerMonitorCover.class, CoverBehavior.MANAGED_FIELD_HOLDER); - private TickableSubscription subscription; + private @Nullable TickableSubscription subscription; private final CoverTextRenderer renderer; @Persisted private final List formatStringArgs = new ArrayList<>(8); @@ -67,7 +65,7 @@ public class ComputerMonitorCover extends CoverBehavior @Getter private List text = new ArrayList<>(); @Persisted - public final CustomItemStackHandler itemStackHandler = new CustomItemStackHandler(8); + public final CustomItemStackHandler itemHandler = new CustomItemStackHandler(8); @Setter private String placeholderSearch = ""; @Setter @@ -84,7 +82,7 @@ public class ComputerMonitorCover extends CoverBehavior public ComputerMonitorCover(CoverDefinition definition, ICoverable coverHolder, Direction attachedSide) { super(definition, coverHolder, attachedSide); renderer = new CoverTextRenderer(this::getText); - for (int i = 0; i < 100; i++) createDisplayTargetBuffer.add(MutableComponent.create(ComponentContents.EMPTY)); + for (int i = 0; i < 100; i++) createDisplayTargetBuffer.add(Component.empty()); } public List getRenderedText() { @@ -93,7 +91,7 @@ public List getRenderedText() { tmp = tmp.stream().map(str -> '{' + str + '}').toList(); return PlaceholderHandler.processPlaceholders( GTStringUtils.replace(s, "\\{}", tmp), - new PlaceholderContext(coverHolder.getLevel(), coverHolder.getPos(), attachedSide, itemStackHandler, + new PlaceholderContext(coverHolder.getLevel(), coverHolder.getPos(), attachedSide, itemHandler, this, new MultiLineComponent(text))); } @@ -135,7 +133,7 @@ public Widget createUIWidget() { formatStringInput.setTextResponder((s) -> formatStringLines.set(finalI, s)); mainPage.addWidget(formatStringInput); SlotWidget slot = new com.gregtechceu.gtceu.api.gui.widget.SlotWidget( - itemStackHandler, + itemHandler, i, horizontalPadding + 50, 20 * i); @@ -212,8 +210,8 @@ private void update() { setRedstoneSignalOutput(0); text = getRenderedText(); } catch (RuntimeException e) { - text = GTUtil - .list(Component.translatable("gtceu.computer_monitor_cover.error.exception", e.getMessage())); + text = GTUtil.list( + Component.translatable("gtceu.computer_monitor_cover.error.exception", e.getMessage())); } } } @@ -235,40 +233,31 @@ public boolean canConnectRedstone() { public List getAdditionalDrops() { List drops = super.getAdditionalDrops(); for (int i = 0; i < 8; i++) { - if (!itemStackHandler.getStackInSlot(i).isEmpty()) - drops.add(itemStackHandler.getStackInSlot(i)); + if (!itemHandler.getStackInSlot(i).isEmpty()) { + drops.add(itemHandler.getStackInSlot(i)); + } } return drops; } @Override public InteractionResult onDataStickUse(Player player, ItemStack dataStick) { - CompoundTag tag = dataStick.getTagElement("computer_monitor_cover_config"); - if (tag == null) return InteractionResult.FAIL; - List stringLines = new ArrayList<>(); - ListTag stringLinesTag = tag.getList("lines", Tag.TAG_STRING); - for (int i = 0; i < stringLinesTag.size(); i++) stringLines.add(stringLinesTag.getString(i)); + ComputerMonitorConfig config = dataStick.get(GTDataComponents.COMPUTER_MONITOR_CONFIG); + if (config == null) return InteractionResult.FAIL; + formatStringLines.clear(); - formatStringLines.addAll(stringLines); - List stringArgs = new ArrayList<>(); - ListTag stringArgsTag = tag.getList("args", Tag.TAG_STRING); - for (int i = 0; i < stringArgsTag.size(); i++) stringArgs.add(stringArgsTag.getString(i)); + formatStringLines.addAll(config.lines()); + formatStringArgs.clear(); - formatStringArgs.addAll(stringArgs); - updateInterval = tag.getInt("updateInterval"); - return InteractionResult.SUCCESS; + formatStringArgs.addAll(config.args()); + updateInterval = config.updateInterval(); + return InteractionResult.sidedSuccess(player.level().isClientSide); } @Override public InteractionResult onDataStickShiftUse(Player player, ItemStack dataStick) { - CompoundTag tag = dataStick.getOrCreateTagElement("computer_monitor_cover_config"); - ListTag stringLinesTag = new ListTag(); - formatStringLines.forEach(line -> stringLinesTag.add(StringTag.valueOf(line))); - tag.put("lines", stringLinesTag); - ListTag stringArgsTag = new ListTag(); - formatStringArgs.forEach(line -> stringArgsTag.add(StringTag.valueOf(line))); - tag.put("args", stringArgsTag); - tag.putInt("updateInterval", updateInterval); - return InteractionResult.SUCCESS; + dataStick.set(GTDataComponents.COMPUTER_MONITOR_CONFIG, + new ComputerMonitorConfig(formatStringLines, formatStringArgs, updateInterval)); + return InteractionResult.sidedSuccess(player.level().isClientSide); } } diff --git a/src/main/java/com/gregtechceu/gtceu/common/cover/WirelessTransmitterCover.java b/src/main/java/com/gregtechceu/gtceu/common/cover/WirelessTransmitterCover.java index b66b219ca89..a7e0dc316d6 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/cover/WirelessTransmitterCover.java +++ b/src/main/java/com/gregtechceu/gtceu/common/cover/WirelessTransmitterCover.java @@ -10,7 +10,7 @@ import net.minecraft.MethodsReturnNonnullByDefault; import net.minecraft.core.Direction; -import net.minecraft.network.chat.ComponentContents; +import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; @@ -36,7 +36,7 @@ public class WirelessTransmitterCover extends CoverBehavior public WirelessTransmitterCover(CoverDefinition definition, ICoverable coverHolder, Direction attachedSide) { super(definition, coverHolder, attachedSide); - for (int i = 0; i < 100; i++) createDisplayTargetBuffer.add(MutableComponent.create(ComponentContents.EMPTY)); + for (int i = 0; i < 100; i++) createDisplayTargetBuffer.add(Component.empty()); } @Override diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/BindingData.java b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/BindingData.java new file mode 100644 index 00000000000..d388598de8b --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/BindingData.java @@ -0,0 +1,62 @@ +package com.gregtechceu.gtceu.common.item.datacomponents; + +import net.minecraft.core.UUIDUtil; +import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.component.TooltipProvider; +import net.minecraft.world.level.EntityGetter; +import net.neoforged.neoforge.common.UsernameCache; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import org.jetbrains.annotations.Nullable; + +import java.util.UUID; +import java.util.function.Consumer; + +public record BindingData(int permissionLevel, UUID uuid) implements TooltipProvider { + + // spotless:off + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ExtraCodecs.NON_NEGATIVE_INT.fieldOf("permission_level").forGetter(BindingData::permissionLevel), + UUIDUtil.STRING_CODEC.fieldOf("uuid").forGetter(BindingData::uuid) + ).apply(instance, BindingData::new)); + + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.VAR_INT, BindingData::permissionLevel, + UUIDUtil.STREAM_CODEC, BindingData::uuid, + BindingData::new + ); + //spotless:on + + public @Nullable Component getBoundPlayerName(@Nullable EntityGetter level) { + if (level != null) { + Player player = level.getPlayerByUUID(this.uuid); + if (player != null) { + return player.getDisplayName(); + } + } else { + String lastUsername = UsernameCache.getLastKnownUsername(this.uuid); + if (lastUsername != null) { + return Component.literal(lastUsername); + } + } + return null; + } + + @Override + public void addToTooltip(Item.TooltipContext context, Consumer tooltipAdder, TooltipFlag tooltipFlag) { + Component displayName = getBoundPlayerName(context.level()); + if (displayName == null) { + displayName = Component.translatable("gtceu.tooltip.player_name.unknown"); + } + + tooltipAdder.accept(Component.translatable("gtceu.tooltip.player_bind", displayName)); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/ComputerMonitorConfig.java b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/ComputerMonitorConfig.java new file mode 100644 index 00000000000..4e4a36dda21 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/ComputerMonitorConfig.java @@ -0,0 +1,49 @@ +package com.gregtechceu.gtceu.common.item.datacomponents; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; +import net.minecraft.util.ExtraCodecs; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.item.component.TooltipProvider; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import io.netty.buffer.ByteBuf; +import lombok.With; + +import java.util.Collections; +import java.util.List; +import java.util.function.Consumer; + +public record ComputerMonitorConfig(@With List lines, @With List args, @With int updateInterval) + implements TooltipProvider { + + //spotless:off + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + Codec.STRING.listOf().fieldOf("lines").forGetter(ComputerMonitorConfig::lines), + Codec.STRING.listOf().fieldOf("arguments").forGetter(ComputerMonitorConfig::args), + ExtraCodecs.POSITIVE_INT.fieldOf("update_interval").forGetter(ComputerMonitorConfig::updateInterval) + ).apply(instance, ComputerMonitorConfig::new)); + public static final StreamCodec STREAM_CODEC = StreamCodec.composite( + ByteBufCodecs.STRING_UTF8.apply(ByteBufCodecs.list()), ComputerMonitorConfig::lines, + ByteBufCodecs.STRING_UTF8.apply(ByteBufCodecs.list()), ComputerMonitorConfig::args, + ByteBufCodecs.VAR_INT, ComputerMonitorConfig::updateInterval, + ComputerMonitorConfig::new + ); + //spotless:on + + public static final ComputerMonitorConfig EMPTY = new ComputerMonitorConfig(Collections.emptyList(), + Collections.emptyList(), 100); + + public ComputerMonitorConfig { + lines = Collections.unmodifiableList(lines); + args = Collections.unmodifiableList(args); + } + + @Override + public void addToTooltip(Item.TooltipContext context, Consumer tooltipAdder, TooltipFlag tooltipFlag) { + tooltipAdder.accept(Component.translatable("gtceu.tooltip.computer_monitor_config")); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/FormatStringList.java b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/FormatStringList.java new file mode 100644 index 00000000000..ab0eab43b09 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/FormatStringList.java @@ -0,0 +1,69 @@ +package com.gregtechceu.gtceu.common.item.datacomponents; + +import net.minecraft.network.codec.ByteBufCodecs; +import net.minecraft.network.codec.StreamCodec; + +import com.mojang.serialization.Codec; +import io.netty.buffer.ByteBuf; + +import java.util.AbstractList; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public record FormatStringList(List lines) { + + public static final Codec CODEC = Codec.STRING.listOf() + .xmap(FormatStringList::new, FormatStringList::lines); + public static final StreamCodec STREAM_CODEC = ByteBufCodecs.STRING_UTF8 + .apply(ByteBufCodecs.list()) + .map(FormatStringList::new, FormatStringList::lines); + + public static final FormatStringList EMPTY = new FormatStringList(Collections.emptyList()); + + public FormatStringList { + lines = Collections.unmodifiableList(lines); + } + + public Mutable mutable() { + return new Mutable(this.lines); + } + + public static class Mutable extends AbstractList { + + private final List lines; + + public Mutable(List lines) { + this.lines = new ArrayList<>(lines); + } + + public FormatStringList toImmutable() { + return new FormatStringList(this.lines); + } + + @Override + public String get(int index) { + return lines.get(index); + } + + @Override + public int size() { + return lines.size(); + } + + @Override + public boolean add(String s) { + return lines.add(s); + } + + @Override + public boolean remove(Object o) { + return lines.remove(o); + } + + @Override + public String remove(int index) { + return lines.remove(index); + } + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/TextLineList.java b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/TextLineList.java new file mode 100644 index 00000000000..9cf9a65d329 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/TextLineList.java @@ -0,0 +1,39 @@ +package com.gregtechceu.gtceu.common.item.datacomponents; + +import com.gregtechceu.gtceu.api.placeholder.MultiLineComponent; + +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.ComponentSerialization; +import net.minecraft.util.Mth; + +import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import lombok.With; + +import java.util.Collections; +import java.util.List; + +public record TextLineList(@With List lines, @With float scale) { + + // spotless:off + public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( + ComponentSerialization.CODEC.listOf().fieldOf("lines").forGetter(TextLineList::lines), + Codec.FLOAT.fieldOf("scale").forGetter(TextLineList::scale) + ).apply(instance, TextLineList::new)); + // spotless:on + + public static final TextLineList EMPTY = new TextLineList(Collections.emptyList(), 1.0f); + + public TextLineList { + lines = Collections.unmodifiableList(lines); + scale = Mth.clamp(scale, 0.0001f, 1000f); + } + + public MultiLineComponent toMultiLineComponent() { + MultiLineComponent multiLine = new MultiLineComponent(); + for (Component c : this.lines) { + multiLine.add(c.copy()); + } + return multiLine; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/data/item/GTDataComponents.java b/src/main/java/com/gregtechceu/gtceu/data/item/GTDataComponents.java index 7f2e61d76d7..7868b29504f 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/item/GTDataComponents.java +++ b/src/main/java/com/gregtechceu/gtceu/data/item/GTDataComponents.java @@ -9,6 +9,7 @@ import com.gregtechceu.gtceu.api.material.material.Material; import com.gregtechceu.gtceu.api.registry.GTRegistries; import com.gregtechceu.gtceu.common.item.behavior.ItemMagnetBehavior; +import com.gregtechceu.gtceu.common.item.datacomponents.*; import com.gregtechceu.gtceu.common.item.tool.behavior.ToolModeSwitchBehavior; import com.gregtechceu.gtceu.utils.ResearchManager; @@ -20,6 +21,8 @@ import net.minecraft.util.Unit; import net.minecraft.world.item.component.CustomData; import net.minecraft.world.item.enchantment.ItemEnchantments; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import net.neoforged.neoforge.fluids.SimpleFluidContent; import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredRegister; @@ -94,6 +97,7 @@ public class GTDataComponents { public static final DeferredHolder, DataComponentType> SCANNER_MODE = DATA_COMPONENTS .registerComponentType("scanner_mode", builder -> builder.persistent(Codec.BYTE).networkSynchronized(ByteBufCodecs.BYTE)); + public static final DeferredHolder, DataComponentType> SIMPLE_FLUID_FILTER = DATA_COMPONENTS .registerComponentType("simple_fluid_filter", builder -> builder.persistent(SimpleFluidFilter.CODEC)); public static final DeferredHolder, DataComponentType> SIMPLE_ITEM_FILTER = DATA_COMPONENTS @@ -106,12 +110,17 @@ public class GTDataComponents { builder -> builder.persistent(SmartItemFilter.SmartFilteringMode.CODEC)); public static final DeferredHolder, DataComponentType> CIRCUIT_CONFIG = DATA_COMPONENTS .registerComponentType("circuit_config", builder -> builder.persistent(Codec.INT)); + public static final DeferredHolder, DataComponentType> FLUID_CONTENT = DATA_COMPONENTS .registerComponentType("fluid_content", builder -> builder.persistent(SimpleFluidContent.CODEC) .networkSynchronized(SimpleFluidContent.STREAM_CODEC)); public static final DeferredHolder, DataComponentType> ENERGY_CONTENT = DATA_COMPONENTS .registerComponentType("energy_content", builder -> builder.persistent(SimpleEnergyContent.CODEC) .networkSynchronized(SimpleEnergyContent.STREAM_CODEC)); + + public static final DeferredHolder, DataComponentType> BINDING_DATA = DATA_COMPONENTS + .registerComponentType("binding_data", builder -> builder.persistent(BindingData.CODEC) + .networkSynchronized(BindingData.STREAM_CODEC)); public static final DeferredHolder, DataComponentType> DATA_COPY_POS = DATA_COMPONENTS .registerComponentType("data_copy_pos", builder -> builder.persistent(BlockPos.CODEC) .networkSynchronized(BlockPos.STREAM_CODEC)); @@ -119,6 +128,22 @@ public class GTDataComponents { .registerComponentType("data_copy_tag", builder -> builder.persistent(CustomData.CODEC) .networkSynchronized(CustomData.STREAM_CODEC)); + public static final DeferredHolder, DataComponentType> FORMAT_STRING_LIST = DATA_COMPONENTS + .registerComponentType("format_string_list", builder -> builder.persistent(FormatStringList.CODEC) + .networkSynchronized(FormatStringList.STREAM_CODEC)); + public static final DeferredHolder, DataComponentType> COMPUTER_MONITOR_DATA = DATA_COMPONENTS + .registerComponentType("computer_monitor_cover_data", builder -> builder.persistent(FormatStringList.CODEC) + .networkSynchronized(FormatStringList.STREAM_CODEC)); + public static final DeferredHolder, DataComponentType> COMPUTER_MONITOR_CONFIG = DATA_COMPONENTS + .registerComponentType("computer_monitor_cover_config", + builder -> builder.persistent(ComputerMonitorConfig.CODEC) + .networkSynchronized(ComputerMonitorConfig.STREAM_CODEC)); + public static final DeferredHolder, DataComponentType> COMPUTER_MONITOR_P = DATA_COMPONENTS + .registerComponentType("computer_monitor_cover_p", builder -> builder.persistent(Codec.INT) + .networkSynchronized(ByteBufCodecs.VAR_INT)); + public static final DeferredHolder, DataComponentType> TEXT_LINE_LIST = DATA_COMPONENTS + .registerComponentType("text_line_list", builder -> builder.persistent(TextLineList.CODEC)); + // machine info public static final DeferredHolder, DataComponentType> LARGE_ITEM_CONTENT = DATA_COMPONENTS .registerComponentType("large_item_content", builder -> builder @@ -137,13 +162,12 @@ public class GTDataComponents { builder -> builder.persistent(Unit.CODEC).networkSynchronized(UNIT_STREAM_CODEC)); // misc - public static final DeferredHolder, DataComponentType> FACADE = DATA_COMPONENTS - .registerComponentType("facade", - builder -> builder.persistent(FacadeWrapper.CODEC).networkSynchronized(FacadeWrapper.STREAM_CODEC)); + public static final DeferredHolder, DataComponentType> FACADE = DATA_COMPONENTS + .registerComponentType("facade", builder -> builder.persistent(BlockState.CODEC) + .networkSynchronized(ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY))); public static final DeferredHolder, DataComponentType> LAMP_DATA = DATA_COMPONENTS - .registerComponentType("lamp", - builder -> builder.persistent(LampBlockItem.LampData.CODEC) - .networkSynchronized(LampBlockItem.LampData.STREAM_CODEC)); + .registerComponentType("lamp", builder -> builder.persistent(LampBlockItem.LampData.CODEC) + .networkSynchronized(LampBlockItem.LampData.STREAM_CODEC)); public static final DeferredHolder, DataComponentType> LIGHTER_OPEN = DATA_COMPONENTS .registerComponentType("lighter_open", builder -> builder.persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL)); diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTPlaceholders.java b/src/main/java/com/gregtechceu/gtceu/data/placeholder/GTPlaceholders.java similarity index 73% rename from src/main/java/com/gregtechceu/gtceu/common/data/GTPlaceholders.java rename to src/main/java/com/gregtechceu/gtceu/data/placeholder/GTPlaceholders.java index 4b83e859957..a5604b3dc10 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTPlaceholders.java +++ b/src/main/java/com/gregtechceu/gtceu/data/placeholder/GTPlaceholders.java @@ -1,38 +1,36 @@ -package com.gregtechceu.gtceu.common.data; +package com.gregtechceu.gtceu.data.placeholder; import com.gregtechceu.gtceu.api.GTValues; import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper; import com.gregtechceu.gtceu.api.capability.IEnergyContainer; import com.gregtechceu.gtceu.api.capability.IWorkable; import com.gregtechceu.gtceu.api.cover.filter.ItemFilter; -import com.gregtechceu.gtceu.api.item.ComponentItem; -import com.gregtechceu.gtceu.api.item.component.IDataItem; -import com.gregtechceu.gtceu.api.item.component.IItemComponent; import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMaintenanceMachine; import com.gregtechceu.gtceu.api.placeholder.*; import com.gregtechceu.gtceu.api.placeholder.exceptions.*; import com.gregtechceu.gtceu.common.blockentity.CableBlockEntity; +import com.gregtechceu.gtceu.common.item.datacomponents.BindingData; +import com.gregtechceu.gtceu.common.item.datacomponents.DataItem; +import com.gregtechceu.gtceu.common.item.datacomponents.FormatStringList; +import com.gregtechceu.gtceu.data.item.GTDataComponents; import com.gregtechceu.gtceu.utils.GTStringUtils; import net.minecraft.ChatFormatting; import net.minecraft.commands.CommandSource; import net.minecraft.commands.CommandSourceStack; import net.minecraft.core.Direction; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.server.MinecraftServer; import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.phys.Vec2; import net.minecraft.world.phys.Vec3; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.capability.IFluidHandler; -import net.minecraftforge.items.IItemHandler; -import net.minecraftforge.registries.ForgeRegistries; +import net.neoforged.neoforge.fluids.FluidStack; +import net.neoforged.neoforge.fluids.capability.IFluidHandler; +import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -55,13 +53,16 @@ public static int countItems(String id, @Nullable IItemHandler itemHandler) { public static int countFluids(@Nullable String id, @Nullable IFluidHandler fluidHandler) { if (fluidHandler == null) return 0; - int cnt = 0; + int count = 0; for (int i = 0; i < fluidHandler.getTanks(); i++) { FluidStack fluidStack = fluidHandler.getFluidInTank(i); - String fluidId = Objects.requireNonNull(ForgeRegistries.FLUIDS.getKey(fluidStack.getFluid())).toString(); - if (id == null || fluidId.equals(id)) cnt += fluidStack.getAmount(); + String fluidId = Objects.requireNonNull(BuiltInRegistries.FLUID.getKey(fluidStack.getFluid())).toString(); + + if (id == null || fluidId.equals(id)) { + count += fluidStack.getAmount(); + } } - return cnt; + return count; } public static int countItems(@Nullable ItemFilter filter, @Nullable IItemHandler itemHandler) { @@ -111,17 +112,22 @@ public MultiLineComponent apply(PlaceholderContext ctx, List public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { IItemHandler itemHandler = GTCapabilityHelper.getItemHandler(ctx.level(), ctx.pos(), ctx.side()); - if (args.isEmpty()) return MultiLineComponent.literal(countItems((ItemFilter) null, itemHandler)); - if (args.size() == 1) return MultiLineComponent - .literal(countItems(GTStringUtils.componentsToString(args.get(0)), itemHandler)); - if (GTStringUtils.equals(args.get(0), "filter")) { + if (args.isEmpty()) { + return MultiLineComponent.literal(countItems((ItemFilter) null, itemHandler)); + } + if (args.size() == 1) { + return MultiLineComponent.literal(countItems( + GTStringUtils.componentsToString(args.getFirst()), itemHandler)); + } + if (GTStringUtils.equals(args.getFirst(), "filter")) { int slot = PlaceholderUtils.toInt(args.get(1)); PlaceholderUtils.checkRange("slot index", 1, 8, slot); try { - if (ctx.itemStackHandler() == null) + if (ctx.itemHandler() == null) { throw new NotSupportedException(); + } return MultiLineComponent.literal(countItems( - ItemFilter.loadFilter(ctx.itemStackHandler().getStackInSlot(slot - 1)), itemHandler)); + ItemFilter.loadFilter(ctx.itemHandler().getStackInSlot(slot - 1)), itemHandler)); } catch (NullPointerException e) { throw new MissingItemException("filter", slot); } @@ -138,7 +144,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, if (args.isEmpty()) return MultiLineComponent.literal(countFluids(null, fluidHandler)); if (args.size() == 1) return MultiLineComponent - .literal(countFluids(GTStringUtils.componentsToString(args.get(0)), fluidHandler)); + .literal(countFluids(GTStringUtils.componentsToString(args.getFirst()), fluidHandler)); PlaceholderUtils.checkArgs(args, 1); return MultiLineComponent.empty(); // unreachable } @@ -150,7 +156,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 2, true); try { - if (GTStringUtils.toDouble(args.get(0)) != 0) { + if (GTStringUtils.toDouble(args.getFirst()) != 0) { return args.get(1); } else if (args.size() > 2) return args.get(2); else return MultiLineComponent.empty(); @@ -165,7 +171,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 2); - ChatFormatting color = ChatFormatting.getByName(GTStringUtils.componentsToString(args.get(0))); + ChatFormatting color = ChatFormatting.getByName(GTStringUtils.componentsToString(args.getFirst())); if (color == null) throw new InvalidArgsException(); return new MultiLineComponent(args.get(1).stream().map(c -> c.withStyle(color)).toList()); } @@ -177,7 +183,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1); return new MultiLineComponent( - args.get(0).stream().map(c -> c.withStyle(ChatFormatting.UNDERLINE)).toList()); + args.getFirst().stream().map(c -> c.withStyle(ChatFormatting.UNDERLINE)).toList()); } }); PlaceholderHandler.addPlaceholder(new Placeholder("strike") { @@ -187,7 +193,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1); return new MultiLineComponent( - args.get(0).stream().map(c -> c.withStyle(ChatFormatting.STRIKETHROUGH)).toList()); + args.getFirst().stream().map(c -> c.withStyle(ChatFormatting.STRIKETHROUGH)).toList()); } }); PlaceholderHandler.addPlaceholder(new Placeholder("obf") { @@ -197,7 +203,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1); return new MultiLineComponent( - args.get(0).stream().map(c -> c.withStyle(ChatFormatting.OBFUSCATED)).toList()); + args.getFirst().stream().map(c -> c.withStyle(ChatFormatting.OBFUSCATED)).toList()); } }); PlaceholderHandler.addPlaceholder(new Placeholder("random") { @@ -207,7 +213,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 2); return MultiLineComponent.literal(GTValues.RNG.nextIntBetweenInclusive( - PlaceholderUtils.toInt(args.get(0)), PlaceholderUtils.toInt(args.get(1)))); + PlaceholderUtils.toInt(args.getFirst()), PlaceholderUtils.toInt(args.get(1)))); } }); PlaceholderHandler.addPlaceholder(new Placeholder("repeat") { @@ -216,7 +222,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 2); - int count = PlaceholderUtils.toInt(args.get(0)); + int count = PlaceholderUtils.toInt(args.getFirst()); MultiLineComponent out = MultiLineComponent.empty(); for (int i = 0; i < count; i++) out.append(args.get(1)); return out; @@ -248,7 +254,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1, true); - int i = PlaceholderUtils.toInt(args.get(0)); + int i = PlaceholderUtils.toInt(args.getFirst()); PlaceholderUtils.checkArgs(args, i + 2); return args.get(i + 1); } @@ -259,7 +265,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 2, true); - if (GTStringUtils.equals(args.get(0), "get")) { + if (GTStringUtils.equals(args.getFirst(), "get")) { Direction direction = Direction.byName(GTStringUtils.componentsToString(args.get(1))); if (direction == null) throw new InvalidArgsException(); @@ -281,7 +287,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1); - int i = PlaceholderUtils.toInt(args.get(0)); + int i = PlaceholderUtils.toInt(args.getFirst()); if (ctx.previousText() == null) throw new NotSupportedException(); PlaceholderUtils.checkRange("line", 1, ctx.previousText().size(), i); return MultiLineComponent.of(ctx.previousText().get(i - 1)); @@ -365,7 +371,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1, true); - String arg1 = GTStringUtils.componentsToString(args.get(0)); + String arg1 = GTStringUtils.componentsToString(args.getFirst()); int cnt = -1; for (List arg : args) { if (GTStringUtils.equals(arg, arg1)) cnt++; @@ -382,42 +388,49 @@ public MultiLineComponent apply(PlaceholderContext ctx, try { int slot = PlaceholderUtils.toInt(args.get(1)); PlaceholderUtils.checkRange("slot index", 1, 8, slot); - if (ctx.itemStackHandler() == null) throw new NotSupportedException(); - ItemStack stack = ctx.itemStackHandler().getStackInSlot(slot - 1); - int capacity = -1; - if (stack.getItem() instanceof ComponentItem componentItem) { - for (IItemComponent component : componentItem.getComponents()) { - if (component instanceof IDataItem dataComponent) { - capacity = dataComponent.getCapacity(); - break; - } - } + if (ctx.itemHandler() == null) throw new NotSupportedException(); + + ItemStack stack = ctx.itemHandler().getStackInSlot(slot - 1); + DataItem component = stack.get(GTDataComponents.DATA_ITEM); + if (component == null) { + throw new MissingItemException("any data item", slot); } - if (capacity == -1) throw new MissingItemException("any data item", slot); + int capacity = component.capacity(); + PlaceholderUtils.checkRange("index", 0, capacity - 1, PlaceholderUtils.toInt(args.get(2))); - ListTag data = stack.getOrCreateTag().getList("computer_monitor_cover_data", Tag.TAG_STRING); - while (data.size() <= PlaceholderUtils.toInt(args.get(2))) data.add(StringTag.valueOf("")); - int p = stack.getOrCreateTag().getInt("computer_monitor_cover_p"); - if (GTStringUtils.equals(args.get(2), "")) args.set(2, MultiLineComponent.literal(p)); - if (GTStringUtils.equals(args.get(0), "get")) - return MultiLineComponent - .literal(data.getString(PlaceholderUtils.toInt(args.get(2)) % capacity)); - else if (args.get(0).equalsString("set")) { - data.set(PlaceholderUtils.toInt(args.get(2)) % capacity, - StringTag.valueOf(args.get(3).toString())); - stack.getOrCreateTag().put("computer_monitor_cover_data", data); + + FormatStringList immutableData = stack.get(GTDataComponents.COMPUTER_MONITOR_DATA); + if (immutableData == null) { + throw new MissingItemException("any data item", slot); + } + FormatStringList.Mutable monitorData = immutableData.mutable(); + while (monitorData.size() <= PlaceholderUtils.toInt(args.get(2))) { + monitorData.add(""); + } + + int p = stack.getOrDefault(GTDataComponents.COMPUTER_MONITOR_P, 0); + if (GTStringUtils.equals(args.get(2), "")) { + args.set(2, MultiLineComponent.literal(p)); + } + if (GTStringUtils.equals(args.getFirst(), "get")) { + return MultiLineComponent.literal( + monitorData.get(PlaceholderUtils.toInt(args.get(2)) % capacity)); + } else if (args.getFirst().equalsString("set")) { + monitorData.set(PlaceholderUtils.toInt(args.get(2)) % capacity, args.get(3).toString()); + stack.set(GTDataComponents.COMPUTER_MONITOR_DATA, monitorData.toImmutable()); return MultiLineComponent.empty(); - } else if (args.get(0).equalsString("setp")) { - stack.getOrCreateTag().putInt("computer_monitor_cover_p", - PlaceholderUtils.toInt(args.get(3)) % capacity); + } else if (args.getFirst().equalsString("setp")) { + stack.set(GTDataComponents.COMPUTER_MONITOR_P, PlaceholderUtils.toInt(args.get(3)) % capacity); return MultiLineComponent.empty(); - } else if (args.get(0).equalsString("inc")) { - stack.getOrCreateTag().putInt("computer_monitor_cover_p", (p + 1) % capacity); + } else if (args.getFirst().equalsString("inc")) { + stack.set(GTDataComponents.COMPUTER_MONITOR_P, (p + 1) % capacity); return MultiLineComponent.empty(); - } else if (args.get(0).equalsString("dec")) { - stack.getOrCreateTag().putInt("computer_monitor_cover_p", p == 0 ? capacity - 1 : p - 1); + } else if (args.getFirst().equalsString("dec")) { + stack.set(GTDataComponents.COMPUTER_MONITOR_P, p == 0 ? capacity - 1 : p - 1); return MultiLineComponent.empty(); - } else throw new InvalidArgsException(); + } else { + throw new InvalidArgsException(); + } } catch (IndexOutOfBoundsException e) { throw new InvalidArgsException(); } @@ -441,11 +454,11 @@ public MultiLineComponent apply(PlaceholderContext ctx, List public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1); - int slot = GTStringUtils.toInt(args.get(0)); + int slot = GTStringUtils.toInt(args.getFirst()); PlaceholderUtils.checkRange("slot index", 1, 8, slot); - if (ctx.itemStackHandler() == null) throw new NotSupportedException(); + if (ctx.itemHandler() == null) throw new NotSupportedException(); return MultiLineComponent - .literal(ctx.itemStackHandler().getStackInSlot(slot - 1).getOrCreateTag().toString()); + .literal(ctx.itemHandler().getStackInSlot(slot - 1).getComponents().toString()); } }); PlaceholderHandler.addPlaceholder(new Placeholder("toChars") { @@ -454,9 +467,10 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1); - if (args.get(0).isEmpty()) return MultiLineComponent.empty(); + if (args.getFirst().isEmpty()) return MultiLineComponent.empty(); StringBuilder out = new StringBuilder(); - for (char c : GTStringUtils.componentsToString(args.get(0)).toCharArray()) out.append(c).append(' '); + for (char c : GTStringUtils.componentsToString(args.getFirst()).toCharArray()) + out.append(c).append(' '); return MultiLineComponent.literal(out.substring(0, out.length() - 2)); } }); @@ -466,7 +480,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1); - String arg = args.get(0).toString(); + String arg = args.getFirst().toString(); if (arg.length() != 1) throw new InvalidArgsException(); return MultiLineComponent.literal((int) arg.toCharArray()[0]); } @@ -477,7 +491,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1); - return MultiLineComponent.literal((char) PlaceholderUtils.toInt(args.get(0))); + return MultiLineComponent.literal((char) PlaceholderUtils.toInt(args.getFirst())); } }); PlaceholderHandler.addPlaceholder(new Placeholder("subList") { @@ -486,7 +500,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 2, true); - int l = PlaceholderUtils.toInt(args.get(0)); + int l = PlaceholderUtils.toInt(args.getFirst()); int r = PlaceholderUtils.toInt(args.get(1)); PlaceholderUtils.checkRange("start index", 0, args.size(), l); PlaceholderUtils.checkRange("end index", 0, args.size(), r); @@ -502,7 +516,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 3); - double a = PlaceholderUtils.toDouble(args.get(0)); + double a = PlaceholderUtils.toDouble(args.getFirst()); double b = PlaceholderUtils.toDouble(args.get(2)); return switch (args.get(1).toString()) { case ">" -> MultiLineComponent.literal(a > b ? 1 : 0); @@ -521,40 +535,43 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 2); - int slot = PlaceholderUtils.toInt(args.get(0)); + int slot = PlaceholderUtils.toInt(args.getFirst()); PlaceholderUtils.checkRange("slot index", 1, 8, slot); - if (ctx.itemStackHandler() == null) throw new NotSupportedException(); - ItemStack stack = ctx.itemStackHandler().getStackInSlot(slot - 1); - int capacity = -1; - if (stack.getItem() instanceof ComponentItem componentItem) { - for (IItemComponent component : componentItem.getComponents()) { - if (component instanceof IDataItem dataComponent) { - capacity = dataComponent.getCapacity(); - break; - } - } + if (ctx.itemHandler() == null) throw new NotSupportedException(); + + ItemStack stack = ctx.itemHandler().getStackInSlot(slot - 1); + FormatStringList immutableData = stack.get(GTDataComponents.COMPUTER_MONITOR_DATA); + if (immutableData == null) { + throw new MissingItemException("any data item", slot); } - if (capacity == -1) throw new MissingItemException("any data item", slot); - ListTag tag = stack.getOrCreateTag().getList("computer_monitor_cover_data", Tag.TAG_STRING); + FormatStringList.Mutable monitorData = immutableData.mutable(); + int operationsLeft = 1000; int p = 0; String code = args.get(1).toString(); Stack loops = new Stack<>(); for (int i = 0; i < code.length() && operationsLeft > 0; i++) { - while (tag.size() <= p) tag.add(StringTag.valueOf("0")); - if (tag.getString(p).isEmpty()) tag.set(i, StringTag.valueOf("0")); + while (monitorData.size() <= p) { + monitorData.add("0"); + } + if (monitorData.get(p).isEmpty()) { + monitorData.set(i, "0"); + } try { switch (code.charAt(i)) { - case '+' -> tag.set(p, - StringTag.valueOf(String.valueOf(Integer.parseInt(tag.getString(p)) + 1))); - case '-' -> tag.set(p, - StringTag.valueOf(String.valueOf(Integer.parseInt(tag.getString(p)) - 1))); + case '+' -> monitorData.set(p, + String.valueOf(Integer.parseInt(monitorData.get(p)) + 1)); + case '-' -> monitorData.set(p, + String.valueOf(Integer.parseInt(monitorData.get(p)) - 1)); case '>' -> p++; case '<' -> p--; case '[' -> loops.push(i); case ']' -> { - if (Integer.parseInt(tag.getString(p)) == 0) loops.pop(); - else i = loops.peek(); + if (Integer.parseInt(monitorData.get(p)) == 0) { + loops.pop(); + } else { + i = loops.peek(); + } } default -> throw new PlaceholderException(Component .translatable("gtceu.computer_monitor_cover.error.bf_invalid", i).getString()); @@ -574,60 +591,63 @@ public MultiLineComponent apply(PlaceholderContext ctx, public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 2); - if (ctx.itemStackHandler() == null) throw new NotSupportedException(); - int slot = PlaceholderUtils.toInt(args.get(0)); + if (ctx.itemHandler() == null) throw new NotSupportedException(); + int slot = PlaceholderUtils.toInt(args.getFirst()); PlaceholderUtils.checkRange("slot index", 1, 8, slot); - ItemStack stack = ctx.itemStackHandler().getStackInSlot(slot - 1); - if (!stack.getOrCreateTag().contains("boundPlayerPermLevel")) + ItemStack stack = ctx.itemHandler().getStackInSlot(slot - 1); + + BindingData bindingData = stack.get(GTDataComponents.BINDING_DATA); + if (bindingData == null) { throw new MissingItemException("any data item bound to player", slot); - int perm = stack.getOrCreateTag().getInt("boundPlayerPermLevel"); - Component displayName = Component.Serializer - .fromJson(stack.getOrCreateTag().getString("boundPlayerName")); - if (displayName == null) displayName = Component.literal("Placeholder processor"); - if (ctx.level() instanceof ServerLevel serverLevel) { - MinecraftServer server = serverLevel.getServer(); - MultiLineComponent output = MultiLineComponent.empty(); - UUID playerUUID = null; - try { - playerUUID = UUID.fromString(stack.getOrCreateTag().getString("boundPlayerUUID")); - } catch (RuntimeException ignored) {} - ServerPlayer player = playerUUID == null ? null : server.getPlayerList().getPlayer(playerUUID); - CommandSource customSource = new CommandSource() { - - @Override - public void sendSystemMessage(@NotNull Component message) { - output.append(List.of(message)); - output.appendNewline(); - } + } - @Override - public boolean acceptsSuccess() { - return true; - } + Component displayName = bindingData.getBoundPlayerName(ctx.level()); + if (displayName == null) { + displayName = Component.translatable("gtceu.tooltip.player_name.placeholder_processor"); + } - @Override - public boolean acceptsFailure() { - return true; - } + if (!(ctx.level() instanceof ServerLevel serverLevel)) { + throw new NotSupportedException(); + } + MinecraftServer server = serverLevel.getServer(); + Player player = ctx.level().getPlayerByUUID(bindingData.uuid()); - @Override - public boolean shouldInformAdmins() { - return false; - } - }; - CommandSourceStack source = new CommandSourceStack( - customSource, - ctx.pos() == null ? Vec3.ZERO : ctx.pos().getCenter(), - Vec2.ZERO, - serverLevel, - perm, - displayName.getString(), - displayName, - server, - player); - server.getCommands().performPrefixedCommand(source, args.get(1).toString()); - return output; - } else throw new NotSupportedException(); + MultiLineComponent output = MultiLineComponent.empty(); + CommandSource customSource = new CommandSource() { + + @Override + public void sendSystemMessage(@NotNull Component message) { + output.append(List.of(message)).appendNewline(); + } + + @Override + public boolean acceptsSuccess() { + return true; + } + + @Override + public boolean acceptsFailure() { + return true; + } + + @Override + public boolean shouldInformAdmins() { + return false; + } + }; + + CommandSourceStack source = new CommandSourceStack( + customSource, + ctx.pos() == null ? Vec3.ZERO : ctx.pos().getCenter(), + Vec2.ZERO, + serverLevel, + bindingData.permissionLevel(), + displayName.getString(), + displayName, + server, + player); + server.getCommands().performPrefixedCommand(source, args.get(1).toString()); + return output; } }); PlaceholderHandler.addPlaceholder(new Placeholder("tm") { @@ -643,7 +663,7 @@ public MultiLineComponent apply(PlaceholderContext ctx, List public MultiLineComponent apply(PlaceholderContext ctx, List args) throws PlaceholderException { PlaceholderUtils.checkArgs(args, 1); - long n = PlaceholderUtils.toLong(args.get(0)); + long n = PlaceholderUtils.toLong(args.getFirst()); Map suffixes = Map.of( 1L, "", 1000L, "K", diff --git a/src/main/java/com/gregtechceu/gtceu/forge/CommonEventListener.java b/src/main/java/com/gregtechceu/gtceu/forge/CommonEventListener.java index 7ca63e23dfe..91302f5feef 100644 --- a/src/main/java/com/gregtechceu/gtceu/forge/CommonEventListener.java +++ b/src/main/java/com/gregtechceu/gtceu/forge/CommonEventListener.java @@ -29,6 +29,7 @@ import com.gregtechceu.gtceu.common.item.armor.IStepAssist; import com.gregtechceu.gtceu.common.item.armor.QuarkTechSuite; import com.gregtechceu.gtceu.common.item.behavior.ToggleEnergyConsumerBehavior; +import com.gregtechceu.gtceu.common.item.datacomponents.FormatStringList; import com.gregtechceu.gtceu.common.machine.owner.MachineOwner; import com.gregtechceu.gtceu.common.network.packets.SPacketSendWorldID; import com.gregtechceu.gtceu.common.network.packets.hazard.SPacketAddHazardZone; @@ -44,8 +45,10 @@ import com.gregtechceu.gtceu.integration.map.ClientCacheManager; import com.gregtechceu.gtceu.integration.map.WaypointManager; import com.gregtechceu.gtceu.integration.map.cache.server.ServerCache; +import com.gregtechceu.gtceu.utils.GTStringUtils; import com.gregtechceu.gtceu.utils.TaskHandler; +import net.minecraft.network.chat.Component; import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.Difficulty; @@ -391,6 +394,19 @@ public static void onTooltipEvent(ItemTooltipEvent event) { public static void onAttributeTooltipEvent(AddAttributeTooltipsEvent event) { ItemStack stack = event.getStack(); + if (stack.has(GTDataComponents.BINDING_DATA)) { + stack.addToTooltip(GTDataComponents.BINDING_DATA, event.getContext(), + event::addTooltipLines, event.getContext().flag()); + } + if (stack.has(GTDataComponents.COMPUTER_MONITOR_CONFIG)) { + stack.addToTooltip(GTDataComponents.COMPUTER_MONITOR_CONFIG, event.getContext(), + event::addTooltipLines, event.getContext().flag()); + } + if (stack.has(GTDataComponents.COMPUTER_MONITOR_DATA)) { + FormatStringList list = stack.getOrDefault(GTDataComponents.COMPUTER_MONITOR_DATA, FormatStringList.EMPTY); + event.addTooltipLines(Component.translatable("gtceu.tooltip.computer_monitor_data", + GTStringUtils.toCompactedComponent(list.lines()))); + } if (!stack.has(GTDataComponents.DATA_COPY_POS)) { stack.addToTooltip(GTDataComponents.RESEARCH_ITEM, event.getContext(), event::addTooltipLines, event.getContext().flag()); From 94104969a0cae14c92a396d8b38c0e849671f30f Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Sun, 3 Aug 2025 16:28:12 +0300 Subject: [PATCH 02/17] implement datafixers for the yellow limonite -> limonite rename --- .../com/gregtechceu/gtceu/api/GTCEuAPI.java | 2 +- .../datafixer/fixes/DataItemComponentFix.java | 21 ++++++++++++ .../gtceu/data/datafixer/GTDataFixers.java | 32 ++++++++++++------- .../gtceu/data/datagen/lang/LangHandler.java | 2 ++ .../data/material/FirstDegreeMaterials.java | 3 +- .../gtceu/data/material/GTMaterials.java | 2 -- 6 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/DataItemComponentFix.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/GTCEuAPI.java b/src/main/java/com/gregtechceu/gtceu/api/GTCEuAPI.java index 1079446b14f..3f8b0cc704c 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/GTCEuAPI.java +++ b/src/main/java/com/gregtechceu/gtceu/api/GTCEuAPI.java @@ -22,7 +22,7 @@ public class GTCEuAPI { - public static final int GT_DATA_VERSION = 3; + public static final int GT_DATA_VERSION = 4; public static final String NETWORK_VERSION = "3"; /** Will always be available */ diff --git a/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/DataItemComponentFix.java b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/DataItemComponentFix.java new file mode 100644 index 00000000000..3c996b22eb2 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/DataItemComponentFix.java @@ -0,0 +1,21 @@ +package com.gregtechceu.gtceu.common.datafixer.fixes; + +import net.minecraft.util.datafix.fixes.ItemStackComponentRemainderFix; + +import com.mojang.datafixers.schemas.Schema; +import com.mojang.serialization.Dynamic; +import org.jetbrains.annotations.Nullable; + +public class DataItemComponentFix extends ItemStackComponentRemainderFix { + + public DataItemComponentFix(Schema outputSchema) { + super(outputSchema, "GTDataItemComponentFix", "gtceu:data_item"); + } + + @SuppressWarnings("NullableProblems") // this method is passed to Optional#map, where null is a valid return value. + @Override + protected @Nullable Dynamic fixComponent(Dynamic tag) { + // remove the old tag entirely to be replaced with the new one + return null; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/data/datafixer/GTDataFixers.java b/src/main/java/com/gregtechceu/gtceu/data/datafixer/GTDataFixers.java index c641b38e690..b3cf67f5075 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/datafixer/GTDataFixers.java +++ b/src/main/java/com/gregtechceu/gtceu/data/datafixer/GTDataFixers.java @@ -3,10 +3,7 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.GTCEuAPI; import com.gregtechceu.gtceu.api.datafixer.DataFixesInternals; -import com.gregtechceu.gtceu.common.datafixer.fixes.EntityDamageBehaviorFix; -import com.gregtechceu.gtceu.common.datafixer.fixes.GTItemStackComponentizationFix; -import com.gregtechceu.gtceu.common.datafixer.fixes.GTToolComponentFix; -import com.gregtechceu.gtceu.common.datafixer.fixes.OilVariantsRenameFix; +import com.gregtechceu.gtceu.common.datafixer.fixes.*; import com.gregtechceu.gtceu.config.ConfigHolder; import net.minecraft.util.datafix.DataFixTypes; @@ -63,12 +60,18 @@ public static void addFixers(DataFixerBuilder builder) { builder.addFixer(ItemRenameFix.create(schemaV1, "advanced_nanomuscle_chestplate rename fix", createRenamer("gtceu:avanced_nanomuscle_chestplate", "gtceu:advanced_nanomuscle_chestplate"))); - builder.addFixer(ItemRenameFix.create(schemaV1, "U238 rename fix", - createRenamer(Pattern.compile("gtceu:uranium_"), "gtceu:uranium_238_"))); - builder.addFixer(ItemRenameFix.create(schemaV1, "Pu239 rename fix", - createRenamer(Pattern.compile("gtceu:plutonium_"), "gtceu:plutonium_239_"))); - builder.addFixer(ItemRenameFix.create(schemaV1, "Red granite rename fix", - createRenamer(Pattern.compile("gtceu:granite_red"), "gtceu:red_granite"))); + builder.addFixer(ItemRenameFix.create(schemaV1, "U238 item rename fix", + createRenamer(Pattern.compile("gtceu:(.*)uranium_"), "gtceu:$1uranium_238_"))); + builder.addFixer(BlockRenameFix.create(schemaV1, "U238 block rename fix", + createRenamer(Pattern.compile("gtceu:(.*)uranium_"), "gtceu:$1uranium_238_"))); + builder.addFixer(ItemRenameFix.create(schemaV1, "Pu239 item rename fix", + createRenamer(Pattern.compile("gtceu:(.*)plutonium_"), "gtceu:$1plutonium_239_"))); + builder.addFixer(BlockRenameFix.create(schemaV1, "Pu239 block rename fix", + createRenamer(Pattern.compile("gtceu:(.*)plutonium_"), "gtceu:$1plutonium_239_"))); + builder.addFixer(ItemRenameFix.create(schemaV1, "Red granite item rename fix", + createRenamer(Pattern.compile("gtceu:(.*)granite_red"), "gtceu:$1red_granite"))); + builder.addFixer(BlockRenameFix.create(schemaV1, "Red granite block rename fix", + createRenamer(Pattern.compile("gtceu:(.*)granite_red"), "gtceu:$1red_granite"))); builder.addFixer(ItemRenameFix.create(schemaV1, "Raw oil bucket rename fix", createRenamer(OilVariantsRenameFix.RENAMED_ITEM_IDS))); @@ -78,7 +81,7 @@ public static void addFixers(DataFixerBuilder builder) { builder.addFixer(new GTItemStackComponentizationFix(schemaV1)); Schema schemaV2 = builder.addSchema(2, SAME_NAMESPACED); builder.addFixer(ItemRenameFix.create(schemaV2, "Tungstensteel rename fix", - createRenamer(Pattern.compile("gtceu:tungstensteel"), "gtceu:tungsten_steel"))); + createRenamer(Pattern.compile("gtceu:(.*)tungstensteel"), "gtceu:$1tungsten_steel"))); builder.addFixer(ItemRenameFix.create(schemaV2, "Palladium Substation Casing item rename fix", createRenamer("gtceu:palladium_substation", "gtceu:palladium_substation_casing"))); @@ -88,6 +91,13 @@ public static void addFixers(DataFixerBuilder builder) { Schema schemaV3 = builder.addSchema(3, SAME_NAMESPACED); builder.addFixer(new GTToolComponentFix(schemaV3)); builder.addFixer(new EntityDamageBehaviorFix(schemaV3)); + + Schema schemaV4 = builder.addSchema(4, SAME_NAMESPACED); + builder.addFixer(new DataItemComponentFix(schemaV4)); + builder.addFixer(ItemRenameFix.create(schemaV1, "Limonite rename fix", + createRenamer(Pattern.compile("gtceu:(.*)yellow_limonite"), "gtceu:$1limonite"))); + builder.addFixer(BlockRenameFix.create(schemaV1, "Limonite rename fix", + createRenamer(Pattern.compile("gtceu:(.*)yellow_limonite"), "gtceu:$1limonite"))); } private static UnaryOperator createRenamer(String oldName, String newName) { diff --git a/src/main/java/com/gregtechceu/gtceu/data/datagen/lang/LangHandler.java b/src/main/java/com/gregtechceu/gtceu/data/datagen/lang/LangHandler.java index dd86f60cb4b..53b8669438c 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/datagen/lang/LangHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/data/datagen/lang/LangHandler.java @@ -1420,6 +1420,8 @@ public static void init(RegistrateLangProvider provider) { provider.add("gtceu.tooltip.wireless_transmitter_bind", "Binding to a transmitter cover at %s %s %s facing %s"); provider.add("gtceu.tooltip.computer_monitor_config", "Storing computer monitor cover configuration data"); provider.add("gtceu.tooltip.computer_monitor_data", "Storing data: %s"); + provider.add("gtceu.tooltip.player_name.placeholder_processor", "Placeholder processor"); + provider.add("gtceu.tooltip.player_name.unknown", "Unknown player"); provider.add("gtceu.display_source.computer_monitor_cover", "Computer Monitor Cover"); provider.add("gtceu.display_target.computer_monitor_cover", "Computer Monitor Cover"); diff --git a/src/main/java/com/gregtechceu/gtceu/data/material/FirstDegreeMaterials.java b/src/main/java/com/gregtechceu/gtceu/data/material/FirstDegreeMaterials.java index 08a3af9973c..5c88665da82 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/material/FirstDegreeMaterials.java +++ b/src/main/java/com/gregtechceu/gtceu/data/material/FirstDegreeMaterials.java @@ -738,13 +738,12 @@ public static void register() { .components(Lead, 1, Molybdenum, 1, Oxygen, 4) .buildAndRegister(); - Limonite = new Material.Builder(GTCEu.id("yellow_limonite")) + Limonite = new Material.Builder(GTCEu.id("limonite")) .dust().ore() .color(0xf5e315).secondaryColor(0xc06f33).iconSet(METALLIC) .flags(DECOMPOSITION_BY_CENTRIFUGING, BLAST_FURNACE_CALCITE_DOUBLE) .components(Iron, 1, Hydrogen, 1, Oxygen, 2) .buildAndRegister(); - YellowLimonite = Limonite; YttriumBariumCuprate = new Material.Builder(GTCEu.id("yttrium_barium_cuprate")) .ingot() diff --git a/src/main/java/com/gregtechceu/gtceu/data/material/GTMaterials.java b/src/main/java/com/gregtechceu/gtceu/data/material/GTMaterials.java index 7dfdad0d35a..4579f9e08b6 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/material/GTMaterials.java +++ b/src/main/java/com/gregtechceu/gtceu/data/material/GTMaterials.java @@ -540,8 +540,6 @@ private static void excludeAllGemsButNormal(Material material) { public static Material WroughtIron; public static Material Wulfenite; public static Material Limonite; - @Deprecated - public static Material YellowLimonite; public static Material YttriumBariumCuprate; public static Material NetherQuartz; public static Material CertusQuartz; From e380e916605e8b87075519eb660fd3008da7fb41 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Thu, 20 Nov 2025 19:49:18 +0200 Subject: [PATCH 03/17] fix multiline component codec --- .../gtceu/api/placeholder/MultiLineComponent.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java b/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java index c4a9d7bb5d6..e27ecda321f 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java +++ b/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java @@ -16,16 +16,8 @@ public class MultiLineComponent extends ArrayList { public static final Codec CODEC = ComponentSerialization.CODEC.listOf() - .xmap(list -> { - if (((List) list) instanceof MultiLineComponent multiLine) { - return multiLine; - } - MultiLineComponent multiLine = new MultiLineComponent(); - for (Component c : list) { - multiLine.add(c.copy()); - } - return multiLine; - }, MultiLineComponent::toImmutable); + .xmap(components -> new MultiLineComponent(components.stream().map(Component::copy).toList()), + MultiLineComponent::toImmutable); public MultiLineComponent() {} From 58d5be5bc35af86208e21f6d956eb9678eaf6517 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:16:13 +0300 Subject: [PATCH 04/17] Add back data fixers (why were these even removed??) --- .../api/datafixer/DataFixesInternals.java | 99 +++++++ .../api/datafixer/DataFixesInternalsImpl.java | 82 ++++++ .../gtceu/api/datafixer/EmptySchema.java | 52 ++++ .../gtceu/api/datafixer/FirstSchema.java | 50 ++++ .../gregtechceu/gtceu/api/datafixer/LICENSE | 205 ++++++++++++++ .../api/datafixer/NoOpDataFixesInternals.java | 60 ++++ .../fixes/ToolBehaviorRemainderFix.java | 30 ++ .../gregtechceu/gtceu/common/CommonProxy.java | 1 + .../datafixer/GTDataFixers.java | 2 +- .../fixes/EntityDamageBehaviorFix.java | 43 +++ .../fixes/GTItemStackComponentizationFix.java | 268 ++++++++++++++++++ .../datafixer/fixes/GTToolComponentFix.java | 28 ++ .../datafixer/fixes/OilVariantsRenameFix.java | 20 ++ .../gtceu/common/datafixer/schemas/V0.java | 64 +++++ 14 files changed, 1003 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/gregtechceu/gtceu/api/datafixer/DataFixesInternals.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/datafixer/DataFixesInternalsImpl.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/datafixer/EmptySchema.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/datafixer/FirstSchema.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/datafixer/LICENSE create mode 100644 src/main/java/com/gregtechceu/gtceu/api/datafixer/NoOpDataFixesInternals.java create mode 100644 src/main/java/com/gregtechceu/gtceu/api/datafixer/fixes/ToolBehaviorRemainderFix.java rename src/main/java/com/gregtechceu/gtceu/{data => common}/datafixer/GTDataFixers.java (99%) create mode 100644 src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/EntityDamageBehaviorFix.java create mode 100644 src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/GTItemStackComponentizationFix.java create mode 100644 src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/GTToolComponentFix.java create mode 100644 src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/OilVariantsRenameFix.java create mode 100644 src/main/java/com/gregtechceu/gtceu/common/datafixer/schemas/V0.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/datafixer/DataFixesInternals.java b/src/main/java/com/gregtechceu/gtceu/api/datafixer/DataFixesInternals.java new file mode 100644 index 00000000000..a1fc36791f8 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/datafixer/DataFixesInternals.java @@ -0,0 +1,99 @@ +/* + * Copyright 2022 QuiltMC + * Modified by the Steam 'n' Rails (Railways) team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gregtechceu.gtceu.api.datafixer; + +import com.gregtechceu.gtceu.GTCEu; +import com.gregtechceu.gtceu.config.ConfigHolder; + +import net.minecraft.SharedConstants; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.datafix.DataFixers; + +import com.mojang.datafixers.DSL; +import com.mojang.datafixers.DataFixUtils; +import com.mojang.datafixers.DataFixer; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.serialization.Dynamic; +import org.jetbrains.annotations.*; + +import java.util.function.BiFunction; + +import static com.google.common.base.Preconditions.checkArgument; + +@ApiStatus.Internal +public abstract class DataFixesInternals { + + public static final BiFunction BASE_SCHEMA = (version, parent) -> { + checkArgument(version == 0, "version must be 0"); + checkArgument(parent == null, "parent must be null"); + return get().createBaseSchema(); + }; + + public record DataFixerEntry(DataFixer dataFixer, int currentVersion) {} + + @Contract(pure = true) + @Range(from = 0, to = Integer.MAX_VALUE) + public static int getModDataVersion(@NotNull Dynamic compound) { + return compound.get("GTCEu_DataVersion").asInt(0); + } + + private static DataFixesInternals instance; + + public static @NotNull DataFixesInternals get() { + if (instance == null) { + // Init config in case it's not loaded yet + ConfigHolder.init(); + if (!ConfigHolder.INSTANCE.compat.doDatafixers) { + instance = new NoOpDataFixesInternals(); + return instance; + } + + Schema latestVanillaSchema; + try { + latestVanillaSchema = DataFixers.getDataFixer() + .getSchema(DataFixUtils + .makeKey(SharedConstants.getCurrentVersion().getDataVersion().getVersion())); + } catch (Exception e) { + latestVanillaSchema = null; + } + + if (latestVanillaSchema == null) { + GTCEu.LOGGER.warn("[GTCEuM DFU] Failed to initialize! Either someone stopped DFU from initializing,"); + GTCEu.LOGGER.warn("[GTCEuM DFU] or this Minecraft build is hosed."); + GTCEu.LOGGER.warn("[GTCEuM DFU] Using no-op implementation."); + instance = new NoOpDataFixesInternals(); + } else { + instance = new DataFixesInternalsImpl(latestVanillaSchema); + } + } + + return instance; + } + + public abstract void registerFixer(@Range(from = 0, to = Integer.MAX_VALUE) int currentVersion, + @NotNull DataFixer dataFixer); + + public abstract @Nullable DataFixerEntry getFixerEntry(); + + @Contract(value = "-> new", pure = true) + public abstract @NotNull Schema createBaseSchema(); + + public abstract @NotNull Dynamic updateWithAllFixers(DSL.TypeReference dataFixTypes, + @NotNull Dynamic dynamic); + + public abstract @NotNull CompoundTag addModDataVersions(@NotNull CompoundTag compound); +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/datafixer/DataFixesInternalsImpl.java b/src/main/java/com/gregtechceu/gtceu/api/datafixer/DataFixesInternalsImpl.java new file mode 100644 index 00000000000..ed7963a6090 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/datafixer/DataFixesInternalsImpl.java @@ -0,0 +1,82 @@ +/* + * Copyright 2022 QuiltMC + * Modified by the Steam 'n' Rails (Railways) team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gregtechceu.gtceu.api.datafixer; + +import com.gregtechceu.gtceu.common.datafixer.schemas.V0; + +import net.minecraft.nbt.CompoundTag; + +import com.mojang.datafixers.DSL; +import com.mojang.datafixers.DataFixer; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.serialization.Dynamic; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; + +@ApiStatus.Internal +public final class DataFixesInternalsImpl extends DataFixesInternals { + + private final @NotNull Schema latestVanillaSchema; + + private DataFixerEntry dataFixer; + + public DataFixesInternalsImpl(@NotNull Schema latestVanillaSchema) { + this.latestVanillaSchema = latestVanillaSchema; + + this.dataFixer = null; + } + + @Override + public void registerFixer(@Range(from = 0, to = Integer.MAX_VALUE) int currentVersion, + @NotNull DataFixer dataFixer) { + if (this.dataFixer != null) { + throw new IllegalArgumentException("GTCEu already has a registered data fixer"); + } + + this.dataFixer = new DataFixerEntry(dataFixer, currentVersion); + } + + @Override + public @Nullable DataFixerEntry getFixerEntry() { + return dataFixer; + } + + @Override + public @NotNull Schema createBaseSchema() { + return new V0(0, this.latestVanillaSchema); + } + + @Override + public @NotNull Dynamic updateWithAllFixers(DSL.TypeReference type, @NotNull Dynamic dynamic) { + if (dataFixer != null) { + int modDataVersion = DataFixesInternals.getModDataVersion(dynamic); + dynamic = dataFixer.dataFixer().update(type, dynamic, modDataVersion, dataFixer.currentVersion()); + } + + return dynamic; + } + + @Override + public @NotNull CompoundTag addModDataVersions(@NotNull CompoundTag compound) { + if (dataFixer != null) + compound.putInt("GTCEu_DataVersion", dataFixer.currentVersion()); + + return compound; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/datafixer/EmptySchema.java b/src/main/java/com/gregtechceu/gtceu/api/datafixer/EmptySchema.java new file mode 100644 index 00000000000..d52a41cd072 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/datafixer/EmptySchema.java @@ -0,0 +1,52 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gregtechceu.gtceu.api.datafixer; + +import com.mojang.datafixers.DSL; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.datafixers.types.Type; +import com.mojang.datafixers.types.templates.TypeTemplate; +import it.unimi.dsi.fastutil.objects.Object2ObjectMaps; +import org.jetbrains.annotations.Range; + +import java.util.Map; +import java.util.function.Supplier; + +/** + * Represents an empty {@link Schema}, having no parent and containing no type definitions. + */ +public final class EmptySchema extends FirstSchema { + + /** + * Constructs an empty schema. + * + * @param versionKey the data version key + */ + public EmptySchema(@Range(from = 0, to = Integer.MAX_VALUE) int versionKey) { + super(versionKey); + } + + // Ensure the schema stays empty. + @Override + public void registerType(boolean recursive, DSL.TypeReference type, Supplier template) { + throw new UnsupportedOperationException(); + } + + @Override + protected Map> buildTypes() { + return Object2ObjectMaps.emptyMap(); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/datafixer/FirstSchema.java b/src/main/java/com/gregtechceu/gtceu/api/datafixer/FirstSchema.java new file mode 100644 index 00000000000..a04730bf6d5 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/datafixer/FirstSchema.java @@ -0,0 +1,50 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gregtechceu.gtceu.api.datafixer; + +import com.mojang.datafixers.schemas.Schema; +import com.mojang.datafixers.types.templates.TypeTemplate; +import org.jetbrains.annotations.Range; + +import java.util.Map; +import java.util.function.Supplier; + +public class FirstSchema extends Schema { + + /** + * Creates a schema. + * + * @param versionKey the data version key + */ + public FirstSchema(@Range(from = 0, to = Integer.MAX_VALUE) int versionKey) { + super(versionKey, null); + } + + // all of these methods refer to this.parent without checking if its null + @Override + public void registerTypes(Schema schema, Map> entityTypes, + Map> blockEntityTypes) {} + + @Override + public Map> registerEntities(Schema schema) { + return Map.of(); + } + + @Override + public Map> registerBlockEntities(Schema schema) { + return Map.of(); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/datafixer/LICENSE b/src/main/java/com/gregtechceu/gtceu/api/datafixer/LICENSE new file mode 100644 index 00000000000..ad5b29c1e36 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/datafixer/LICENSE @@ -0,0 +1,205 @@ +Certain portions of the datafixer are taken from the +Quilt Standard Library (https://github.com/QuiltMC/quilt-standard-libraries), +and as such are licensed under the following license: + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/src/main/java/com/gregtechceu/gtceu/api/datafixer/NoOpDataFixesInternals.java b/src/main/java/com/gregtechceu/gtceu/api/datafixer/NoOpDataFixesInternals.java new file mode 100644 index 00000000000..2b3b0481ed7 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/datafixer/NoOpDataFixesInternals.java @@ -0,0 +1,60 @@ +/* + * Copyright 2022 QuiltMC + * Modified by the Steam 'n' Rails (Railways) team + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gregtechceu.gtceu.api.datafixer; + +import net.minecraft.nbt.CompoundTag; + +import com.mojang.datafixers.DSL; +import com.mojang.datafixers.DataFixer; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.serialization.Dynamic; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.Range; + +public class NoOpDataFixesInternals extends DataFixesInternals { + + private final Schema schema; + + public NoOpDataFixesInternals() { + schema = new EmptySchema(0); + } + + @Override + public void registerFixer(@Range(from = 0, to = Integer.MAX_VALUE) int currentVersion, + @NotNull DataFixer dataFixer) {} + + @Override + public @Nullable DataFixerEntry getFixerEntry() { + return null; + } + + @Override + public @NotNull Schema createBaseSchema() { + return schema; + } + + @Override + public @NotNull Dynamic updateWithAllFixers(DSL.TypeReference dataFixTypes, @NotNull Dynamic dynamic) { + return dynamic; + } + + @Override + public @NotNull CompoundTag addModDataVersions(@NotNull CompoundTag compound) { + return compound; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/api/datafixer/fixes/ToolBehaviorRemainderFix.java b/src/main/java/com/gregtechceu/gtceu/api/datafixer/fixes/ToolBehaviorRemainderFix.java new file mode 100644 index 00000000000..8eb3cccdf3a --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/api/datafixer/fixes/ToolBehaviorRemainderFix.java @@ -0,0 +1,30 @@ +package com.gregtechceu.gtceu.api.datafixer.fixes; + +import net.minecraft.util.datafix.fixes.ItemStackComponentRemainderFix; + +import com.mojang.datafixers.schemas.Schema; +import com.mojang.serialization.Dynamic; +import org.jetbrains.annotations.NotNull; + +public abstract class ToolBehaviorRemainderFix extends ItemStackComponentRemainderFix { + + private final String behaviorId; + private final String newBehaviorId; + + public ToolBehaviorRemainderFix(Schema outputSchema, String name, String behaviorId) { + this(outputSchema, name, behaviorId, behaviorId); + } + + public ToolBehaviorRemainderFix(Schema outputSchema, String name, String behaviorId, String newBehaviorId) { + super(outputSchema, name, "gtceu:tool_behaviors"); + this.behaviorId = behaviorId; + this.newBehaviorId = newBehaviorId; + } + + @Override + protected final @NotNull Dynamic fixComponent(@NotNull Dynamic tag) { + return tag.renameAndFixField(behaviorId, newBehaviorId, this::fixBehavior); + } + + protected abstract @NotNull Dynamic fixBehavior(@NotNull Dynamic tag); +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java b/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java index b85f3595920..1c7e875de22 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java +++ b/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java @@ -225,6 +225,7 @@ public static void onRegister(RegisterEvent event) { SyncedKeyMappings.init(); MachineOwner.init(); ChestGenHooks.init(); + GTDataFixers.init(); } @ApiStatus.Internal diff --git a/src/main/java/com/gregtechceu/gtceu/data/datafixer/GTDataFixers.java b/src/main/java/com/gregtechceu/gtceu/common/datafixer/GTDataFixers.java similarity index 99% rename from src/main/java/com/gregtechceu/gtceu/data/datafixer/GTDataFixers.java rename to src/main/java/com/gregtechceu/gtceu/common/datafixer/GTDataFixers.java index b3cf67f5075..cd9b4aa61da 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/datafixer/GTDataFixers.java +++ b/src/main/java/com/gregtechceu/gtceu/common/datafixer/GTDataFixers.java @@ -1,4 +1,4 @@ -package com.gregtechceu.gtceu.data.datafixer; +package com.gregtechceu.gtceu.common.datafixer; import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.GTCEuAPI; diff --git a/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/EntityDamageBehaviorFix.java b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/EntityDamageBehaviorFix.java new file mode 100644 index 00000000000..0290d288936 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/EntityDamageBehaviorFix.java @@ -0,0 +1,43 @@ +package com.gregtechceu.gtceu.common.datafixer.fixes; + +import com.gregtechceu.gtceu.api.datafixer.fixes.ToolBehaviorRemainderFix; + +import com.mojang.datafixers.schemas.Schema; +import com.mojang.serialization.Dynamic; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +public class EntityDamageBehaviorFix extends ToolBehaviorRemainderFix { + + public EntityDamageBehaviorFix(Schema outputSchema) { + super(outputSchema, "EntityDamageBehaviorFix", "gtceu:tool_behaviors"); + } + + @Override + protected @NotNull Dynamic fixBehavior(@NotNull Dynamic tag) { + Optional> bonusList = tag.get("bonus_list").result(); + tag = tag.remove("bonus_list"); + + if (bonusList.isPresent()) { + final Dynamic dynamic = tag; + var map = bonusList.get().asMap(key -> key.asString(""), + value -> value.asFloat(0.0f)); + if (map.isEmpty()) return tag; + + tag = tag.set("bonus_list", tag.createList( + map.entrySet().stream() + .map(entry -> { + Dynamic bonus = dynamic.emptyMap() + .set("bonus", dynamic.createFloat(entry.getValue())); + if (entry.getKey().isEmpty()) { + bonus = bonus.set("entities", bonus.emptyList()); + } else { + bonus = bonus.set("entities", bonus.createString("#" + entry.getKey())); + } + return bonus; + }))); + } + return tag; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/GTItemStackComponentizationFix.java b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/GTItemStackComponentizationFix.java new file mode 100644 index 00000000000..cad802e212e --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/GTItemStackComponentizationFix.java @@ -0,0 +1,268 @@ +package com.gregtechceu.gtceu.common.datafixer.fixes; + +import com.gregtechceu.gtceu.utils.FormattingUtil; + +import net.minecraft.util.datafix.fixes.References; +import net.minecraft.util.datafix.schemas.NamespacedSchema; + +import com.mojang.datafixers.DataFix; +import com.mojang.datafixers.DataFixUtils; +import com.mojang.datafixers.TypeRewriteRule; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.serialization.Dynamic; +import com.mojang.serialization.DynamicOps; +import com.mojang.serialization.OptionalDynamic; + +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Function; +import java.util.function.UnaryOperator; + +public class GTItemStackComponentizationFix extends DataFix { + + private static final Set ARMOR_IDS = Set.of( + "gtceu:nightvision_goggles", + "gtceu:nanomuscle_chestplate", + "gtceu:nanomuscle_leggings", + "gtceu:nanomuscle_boots", + "gtceu:nanomuscle_helmet", + "gtceu:face_mask", + "gtceu:rubber_gloves", + "gtceu:hazmat_chestpiece", + "gtceu:hazmat_leggings", + "gtceu:hazmat_boots", + "gtceu:hazmat_headpiece", + "gtceu:quarktech_chestplate", + "gtceu:quarktech_leggings", + "gtceu:quarktech_boots", + "gtceu:quarktech_helmet", + "gtceu:liquid_fuel_jetpack", + "gtceu:electric_jetpack", + "gtceu:advanced_electric_jetpack", + "gtceu:avanced_nanomuscle_chestplate", + "gtceu:advanced_quarktech_chestplate"); + + public GTItemStackComponentizationFix(Schema outputSchema) { + super(outputSchema, true); + } + + @Override + protected TypeRewriteRule makeRule() { + return this.writeFixAndRead( + "ItemStack componentization: GTCEuM edition", + this.getInputSchema().getType(References.ITEM_STACK), + this.getOutputSchema().getType(References.ITEM_STACK), + dynamic -> { + Optional> optional = ItemStackData.read(dynamic).map(data -> { + fixItemStack(data, data.tag); + return data.write(); + }); + return DataFixUtils.orElse(optional, dynamic); + }); + } + + private static void fixItemStack(ItemStackData data, Dynamic tag) { + // Fix tool info tag + OptionalDynamic gtTool = data.removeTag("GT.Tool"); + if (gtTool.result().isPresent()) { + Dynamic dynamic = tag.emptyMap() + .set("tool_speed", tag.createFloat(gtTool.get("ToolSpeed").asFloat(0.0f))) + .set("attack_damage", tag.createFloat(gtTool.get("AttackDamage").asFloat(0.0f))) + .set("enchantability", tag.createInt(gtTool.get("Enchantability").asInt(0))) + .set("harvest_level", tag.createInt(gtTool.get("HarvestLevel").asInt(0))) + .set("last_crafting_use", tag.createInt(gtTool.get("LastCraftingUse").asInt(0))); + data.setComponent("gtceu:gt_tool", dynamic); + + data.setComponent("minecraft:max_damage", gtTool.get("MaxDamage")); + data.setComponent("minecraft:damage", gtTool.get("Damage")); + OptionalDynamic dynamic1 = gtTool.get("TintColor"); + if (dynamic1.result().isPresent()) { + Dynamic colorDynamic = tag.emptyMap() + .set("rgb", tag.createInt(dynamic1.asInt(0))) + .set("showInTooltip", tag.createBoolean(false)); + data.setComponent("minecraft:dyed_color", colorDynamic); + } + data.setComponent("gtceu:disallow_container_item", gtTool.get("DisallowContainerItem")); + } + + // fix tool behaviors tag + fixGtToolBehaviors(data, tag); + + // Fix power info tags + if (tag.get("Charge").result().isPresent()) { + OptionalDynamic charge = data.removeTag("Charge"); + OptionalDynamic maxCharge = data.removeTag("MaxCharge"); + OptionalDynamic infinite = data.removeTag("Infinite"); + OptionalDynamic dischargeMode = data.removeTag("DischargeMode"); + Dynamic dynamic = tag.emptyMap() + .set("max_charge", tag.createLong(maxCharge.asLong(-1))) + .set("charge", tag.createLong(charge.asLong(0))) + .set("infinite", tag.createBoolean(infinite.asBoolean(false))) + .set("discharge_mode", tag.createBoolean(dischargeMode.asBoolean(false))); + data.setComponent("gtceu:energy_content", dynamic); + } + + // Fix magnet tag + if (tag.get("IsActive").result().isPresent()) { + OptionalDynamic isActive = data.removeTag("IsActive"); + data.setComponent("item_magnet", isActive); + } + + // Fix armors + if (data.is(ARMOR_IDS)) { + OptionalDynamic toggleTimer = data.removeTag("toggleTimer"); + OptionalDynamic hover = data.removeTag("hover"); + OptionalDynamic burnTimer = data.removeTag("burnTimer"); + OptionalDynamic canShare = data.removeTag("canShare"); + OptionalDynamic nightVision = data.removeTag("Nightvision"); + OptionalDynamic consumerTicks = data.removeTag("consumerTicks"); + Dynamic dynamic = tag.emptyMap() + .set("toggle_timer", tag.createByte(toggleTimer.asByte((byte) 0))) + .set("hover", tag.createBoolean(hover.asBoolean(false))) + .set("burn_timer", tag.createShort(burnTimer.asShort((short) 0))) + .set("can_share", tag.createBoolean(canShare.asBoolean(false))) + .set("nightvision", tag.createBoolean(nightVision.asBoolean(false))) + .set("consumer_ticks", tag.createByte(consumerTicks.asByte((byte) 0))); + data.setComponent("gtceu:armor", dynamic); + } + } + + private static void fixGtToolBehaviors(ItemStackData data, Dynamic tag) { + OptionalDynamic gtBehaviorsOpt = data.removeTag("GT.Behaviours"); + + Optional> gtBehaviors = gtBehaviorsOpt.result(); + if (gtBehaviors.isPresent()) { + Dynamic dynamic = tag.emptyMap() + .set("max_column", tag.createInt(gtBehaviors.get().remove("MaxAoEColumn").asInt(0))) + .set("max_row", tag.createInt(gtBehaviors.get().remove("MaxAoERow").asInt(0))) + .set("max_layer", tag.createInt(gtBehaviors.get().remove("MaxAoELayer").asInt(0))) + .set("column", tag.createInt(gtBehaviors.get().remove("AoEColumn").asInt(0))) + .set("row", tag.createInt(gtBehaviors.get().remove("AoERow").asInt(0))) + .set("layer", tag.createInt(gtBehaviors.get().remove("AoELayer").asInt(0))); + data.setComponent("gtceu:aoe", dynamic); + + Map> map = gtBehaviors.get().asMap(val -> val.asString(""), + Function.identity()); + if (!map.isEmpty()) { + dynamic = tag.emptyMap(); + + for (var entry : map.entrySet()) { + if (entry.getKey().equals("RelocateMinedBlocks")) { + data.setComponent("gtceu:relocate_mined_blocks", createEmpty(tag)); + continue; + } else if (entry.getKey().contains("AoE")) { + continue; + } + dynamic = dynamic.set("gtceu:" + FormattingUtil.toLowerCaseUnderscore(entry.getKey()), + createEmpty(tag)); + } + + data.setComponent("gtceu:tool_behaviors", dynamic); + } + } + } + + // I love generics <3 + private static Dynamic createEmpty(Dynamic dynamic) { + return new Dynamic<>(dynamic.getOps(), dynamic.getOps().empty()); + } + + static class ItemStackData { + + private final String item; + private Dynamic components; + private final Dynamic remainder; + Dynamic tag; + + private ItemStackData(String pItem, Dynamic pNbt) { + this.item = NamespacedSchema.ensureNamespaced(pItem); + this.components = pNbt.emptyMap(); + this.tag = pNbt.get("components").get("minecraft:custom_data") + .result().orElseGet(() -> (Dynamic) pNbt.get("tag").orElseEmptyMap()); + this.remainder = pNbt.remove("tag").set("components", pNbt.get("components") + .orElseEmptyMap().remove("minecraft:custom_data")); + } + + public static Optional read(final Dynamic pTag) { + return pTag.get("id") + .asString() + .map(itemId -> new ItemStackData(itemId, pTag)) + .result(); + } + + public OptionalDynamic removeTag(String pKey) { + OptionalDynamic optionaldynamic = this.tag.get(pKey); + this.tag = this.tag.remove(pKey); + return optionaldynamic; + } + + public void setComponent(String pComponent, Dynamic pValue) { + this.components = this.components.set(pComponent, pValue); + } + + public void setComponent(String pComponent, OptionalDynamic pValue) { + pValue.result().ifPresent(p_332105_ -> this.components = this.components.set(pComponent, p_332105_)); + } + + public Dynamic moveTagInto(String pOldKey, Dynamic pTag, String pNewKey) { + Optional> optional = this.removeTag(pOldKey).result(); + return optional.isPresent() ? pTag.set(pNewKey, optional.get()) : pTag; + } + + public void moveTagToComponent(String pKey, String pComponent, Dynamic pTag) { + Optional> optional = this.removeTag(pKey).result(); + if (optional.isPresent() && !optional.get().equals(pTag)) { + this.setComponent(pComponent, optional.get()); + } + } + + public void moveTagToComponent(String pKey, String pComponent) { + this.removeTag(pKey).result().ifPresent(p_330514_ -> this.setComponent(pComponent, p_330514_)); + } + + public void fixSubTag(String pKey, boolean pSkipIfEmpty, UnaryOperator> pFixer) { + OptionalDynamic optionaldynamic = this.tag.get(pKey); + if (!pSkipIfEmpty || !optionaldynamic.result().isEmpty()) { + Dynamic dynamic = optionaldynamic.orElseEmptyMap(); + dynamic = pFixer.apply(dynamic); + if (dynamic.equals(dynamic.emptyMap())) { + this.tag = this.tag.remove(pKey); + } else { + this.tag = this.tag.set(pKey, dynamic); + } + } + } + + public Dynamic write() { + Dynamic dynamic = this.tag; + + if (!this.components.equals(this.tag.emptyMap())) { + dynamic = dynamic.set("components", this.components); + } + + return mergeRemainder(dynamic, this.remainder); + } + + private static Dynamic mergeRemainder(Dynamic tag, Dynamic remainder) { + DynamicOps ops = tag.getOps(); + return ops.getMap(tag.getValue()) + .flatMap(mapLike -> ops.mergeToMap(remainder.convert(ops).getValue(), mapLike)) + .map(object -> new Dynamic<>(ops, object)) + .result() + .orElse(tag); + } + + public boolean is(String pItem) { + return this.item.equals(pItem); + } + + public boolean is(Set pItems) { + return pItems.contains(this.item); + } + + public boolean hasComponent(String pComponent) { + return this.components.get(pComponent).result().isPresent(); + } + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/GTToolComponentFix.java b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/GTToolComponentFix.java new file mode 100644 index 00000000000..1d3bc76e34a --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/GTToolComponentFix.java @@ -0,0 +1,28 @@ +package com.gregtechceu.gtceu.common.datafixer.fixes; + +import net.minecraft.util.datafix.fixes.ItemStackComponentRemainderFix; + +import com.mojang.datafixers.schemas.Schema; +import com.mojang.serialization.Dynamic; +import org.jetbrains.annotations.NotNull; + +import java.util.Optional; + +public class GTToolComponentFix extends ItemStackComponentRemainderFix { + + public GTToolComponentFix(Schema outputSchema) { + super(outputSchema, "GTToolComponentFix", "gtceu:gt_tool"); + } + + @Override + protected @NotNull Dynamic fixComponent(Dynamic tag) { + tag.remove("tool_speed").remove("attack_damage").remove("harvest_level"); + + Optional> lastCraftingUse = tag.get("last_crafting_use").result(); + if (lastCraftingUse.isEmpty()) { + tag = tag.set("last_crafting_use", tag.createInt(0)); + } + + return tag; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/OilVariantsRenameFix.java b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/OilVariantsRenameFix.java new file mode 100644 index 00000000000..b4efc7f6654 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/datafixer/fixes/OilVariantsRenameFix.java @@ -0,0 +1,20 @@ +package com.gregtechceu.gtceu.common.datafixer.fixes; + +import com.google.common.collect.ImmutableMap; + +import java.util.Map; + +public class OilVariantsRenameFix { + + public static final Map RENAMED_ITEM_IDS = ImmutableMap.builder() + .put("gtceu:oil_heavy_bucket", "gtceu:heavy_oil_bucket") + .put("gtceu:oil_light_bucket", "gtceu:light_oil_bucket") + .put("gtceu:oil_medium_bucket", "gtceu:raw_oil_bucket") + .build(); + + public static final Map RENAMED_BLOCK_IDS = ImmutableMap.builder() + .put("gtceu:oil_heavy", "gtceu:heavy_oil") + .put("gtceu:oil_light", "gtceu:light_oil") + .put("gtceu:oil_medium", "gtceu:raw_oil") + .build(); +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/datafixer/schemas/V0.java b/src/main/java/com/gregtechceu/gtceu/common/datafixer/schemas/V0.java new file mode 100644 index 00000000000..09d080e9415 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/datafixer/schemas/V0.java @@ -0,0 +1,64 @@ +package com.gregtechceu.gtceu.common.datafixer.schemas; + +import com.gregtechceu.gtceu.api.machine.MachineDefinition; +import com.gregtechceu.gtceu.api.registry.GTRegistries; +import com.gregtechceu.gtceu.common.data.GTReferences; + +import net.minecraft.util.datafix.fixes.References; +import net.minecraft.util.datafix.schemas.NamespacedSchema; + +import com.mojang.datafixers.DSL; +import com.mojang.datafixers.schemas.Schema; +import com.mojang.datafixers.types.templates.TypeTemplate; + +import java.util.*; +import java.util.function.Supplier; + +public class V0 extends NamespacedSchema { + + public V0(int versionKey, Schema parent) { + super(versionKey, parent); + } + + @Override + public void registerTypes(Schema schema, Map> entityTypes, + Map> blockEntityTypes) { + super.registerTypes(schema, entityTypes, blockEntityTypes); + schema.registerType(false, GTReferences.MATERIAL_NAME, () -> DSL.constType(namespacedString())); + } + + @Override + public Map> registerBlockEntities(Schema schema) { + Map> map = super.registerBlockEntities(schema); + for (MachineDefinition definition : GTRegistries.MACHINES) { + registerInventory(schema, map, definition.getId().toString()); + } + return map; + } + + protected static void registerInventory(Schema schema, Map> map, String name) { + schema.register(map, name, () -> DSL.or( + DSL.fields( + "importItems", + DSL.field("storage", + DSL.field("Items", + DSL.list(References.ITEM_STACK.in(schema)))), + "exportItems", + DSL.field("storage", + DSL.field("Items", + DSL.list(References.ITEM_STACK.in(schema))))), + DSL.or( + DSL.fields( + "inventory", + DSL.field("storage", + DSL.field("Items", + DSL.list(References.ITEM_STACK.in(schema))))), + DSL.or( + DSL.fields( + "cache", + DSL.field("storage", + DSL.field("Items", + DSL.list(References.ITEM_STACK.in(schema))))), + DSL.remainder())))); + } +} From 33a45b76726c34c5b7acac1b20f8d36efad1e206 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:18:48 +0300 Subject: [PATCH 05/17] fix the enum extension JSON being fucked up (@gustovafing your fault) --- src/main/resources/META-INF/enum_extensions.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/META-INF/enum_extensions.json b/src/main/resources/META-INF/enum_extensions.json index ec517e59218..f05c43e0991 100644 --- a/src/main/resources/META-INF/enum_extensions.json +++ b/src/main/resources/META-INF/enum_extensions.json @@ -5,7 +5,7 @@ "name": "GTCEU_RUBBER", "constructor": "(Ljava/util/function/Supplier;Ljava/lang/String;Ljava/util/function/Supplier;Ljava/util/function/Supplier;Ljava/util/function/Supplier;Z)V", "parameters": { - "class": "com/gregtechceu/gtceu/data/inject/GTEnumProxies", + "class": "com/gregtechceu/gtceu/common/data/GTEnumProxies", "field": "RUBBER_BOAT_PROXY" } }, @@ -14,7 +14,7 @@ "name": "GTCEU_TREATED_WOOD", "constructor": "(Ljava/util/function/Supplier;Ljava/lang/String;Ljava/util/function/Supplier;Ljava/util/function/Supplier;Ljava/util/function/Supplier;Z)V", "parameters": { - "class": "com/gregtechceu/gtceu/data/inject/GTEnumProxies", + "class": "com/gregtechceu/gtceu/common/data/GTEnumProxies", "field": "TREATED_WOOD_BOAT_PROXY" } } From adc65c3cf71842cdcfe1eb34785235abab3718b2 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:19:07 +0300 Subject: [PATCH 06/17] why would test dependencies be JiJ'd?? --- dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.gradle b/dependencies.gradle index dbb4ccdcf51..13a83428d8c 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,7 +1,7 @@ dependencies { compileOnly(libs.jetbrains.annotations) - testJarJar(testApi(libs.testframework.get())) + testApi(libs.testframework.get()) jarJar(api(forge.ldlib.get())) From a01a38a6de033f05529a9f191fe04798dce1d189 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:22:13 +0300 Subject: [PATCH 07/17] Fix wack ass ConfigHolder revert --- .../gtceu/config/ConfigHolder.java | 127 +++++++++++++++--- 1 file changed, 109 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java b/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java index 5b46cbc0b44..425d69dd673 100644 --- a/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java +++ b/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java @@ -2,12 +2,15 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.GTCEuAPI; +import com.gregtechceu.gtceu.api.GTValues; import net.minecraft.commands.Commands; +import net.minecraft.resources.ResourceLocation; import dev.toma.configuration.Configuration; import dev.toma.configuration.config.Config; import dev.toma.configuration.config.Configurable; +import dev.toma.configuration.config.UpdateRestrictions; import dev.toma.configuration.config.format.ConfigFormats; import org.jetbrains.annotations.ApiStatus; @@ -54,115 +57,150 @@ public static class RecipeConfigs { @Configurable @Configurable.Comment({ "Whether to generate Flawed and Chipped Gems for materials and recipes involving them.", "Useful for mods like TerraFirmaCraft.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean generateLowQualityGems = false; // default false @Configurable @Configurable.Comment({ "Whether to remove Block/Ingot compression and decompression in the Crafting Table.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean disableManualCompression = true; // default true @Configurable @Configurable.Comment({ "Change the recipe of Rods in the Lathe to 1 Rod and 2 Small Piles of Dust, instead of 2 Rods.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean harderRods = true; // default true @Configurable @Configurable.Comment({ "Whether to make crafting recipes for Bricks, Firebricks, Nether Bricks, and Coke Bricks harder.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean harderBrickRecipes = false; // default false @Configurable @Configurable.Comment({ "Whether to nerf Wood crafting to 2 Planks from 1 Log, and 2 Sticks from 2 Planks.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean nerfWoodCrafting = false; // default false @Configurable @Configurable.Comment({ "Whether to make Wood related recipes harder.", "Excludes sticks and planks.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean hardWoodRecipes = false; // default false @Configurable @Configurable.Comment({ "Recipes for Buckets, Cauldrons, Hoppers, and Iron Bars" + " require Iron Plates, Rods, and more.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean hardIronRecipes = true; // default true @Configurable @Configurable.Comment({ "Whether to make Redstone related recipes harder.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean hardRedstoneRecipes = false; // default false @Configurable @Configurable.Comment({ "Whether to make Vanilla Tools and Armor recipes harder.", "Excludes Flint and Steel, and Buckets.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean hardToolArmorRecipes = false; // default false @Configurable @Configurable.Comment({ "Whether to make miscellaneous recipes harder.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean hardMiscRecipes = false; // default false @Configurable @Configurable.Comment({ "Whether to make Glass related recipes harder. Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean hardGlassRecipes = true; // default true @Configurable @Configurable.Comment({ "Whether to nerf the Paper crafting recipe.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean nerfPaperCrafting = true; // default true @Configurable @Configurable.Comment({ "Recipes for items like Iron Doors, Trapdoors, Anvil" + " require Iron Plates, Rods, and more.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean hardAdvancedIronRecipes = true; // default true @Configurable @Configurable.Comment({ "Whether to make coloring blocks like Concrete or Glass harder.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean hardDyeRecipes = false; // default false @Configurable @Configurable.Comment({ "Whether to remove charcoal smelting recipes from the vanilla furnace.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean harderCharcoalRecipe = true; // default true @Configurable @Configurable.Comment({ "Whether to make the Flint and Steel recipe require steel parts.", "Default: true." }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean flintAndSteelRequireSteel = true; // default true @Configurable @Configurable.Comment({ "Whether to remove Vanilla Block Recipes from the Crafting Table.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean removeVanillaBlockRecipes = false; // default false @Configurable @Configurable.Comment({ "Whether to remove Vanilla TNT Recipe from the Crafting Table.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean removeVanillaTNTRecipe = true; // default true @Configurable @Configurable.Comment({ "How many Multiblock Casings to make per craft. Either 1, 2, or 3.", "Default: 2" }) @Configurable.Range(min = 1, max = 3) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public int casingsPerCraft = 2; @Configurable @Configurable.Comment({ "Whether to nerf the output amounts of the first circuit in a set to 1 (from 2) and SoC to 2 (from 4).", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean harderCircuitRecipes = false; @Configurable @Configurable.Comment({ "Whether to nerf machine controller recipes.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean hardMultiRecipes = false; // default false @Configurable @Configurable.Comment({ "Whether tools should have enchants or not. Like the flint sword getting fire aspect.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean enchantedTools = false; @Configurable @Configurable.Comment({ "Whether to enable macerator decomposition recycling", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean enableMaceratorRecycling = true; @Configurable @Configurable.Comment({ "Percentage yield of macerator decomposition recycling outputs, 1.0 means 100%", "Default: 1.0f" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) @Configurable.DecimalRange(min = 0.0f, max = 1.0f) public float maceratorRecyclingYield = 1.0f; @Configurable @Configurable.Comment({ "Whether to enable arc furnace decomposition recycling", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean enableArcRecycling = true; @Configurable @Configurable.Comment({ "Percentage yield of arc furnace decomposition recycling outputs, 1.0 means 100%", "Default: 1.0f" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) @Configurable.DecimalRange(min = 0.0f, max = 1.0f) public float arcRecyclingYield = 1.0f; @Configurable @Configurable.Comment({ "Whether to enable extractor decomposition recycling", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean enableExtractorRecycling = true; @Configurable @Configurable.Comment({ "Percentage yield of extractor decomposition recycling outputs, 1.0 means 100%", "Default: 1.0f" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) @Configurable.DecimalRange(min = 0.0f, max = 1.0f) public float extractorRecyclingYield = 1.0f; } public static class CompatibilityConfigs { + @Configurable + @Configurable.Comment({ "Whether to run datafixers on world load.", + "Do note that mods like ModernFix will interfere with this.", + "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) + public boolean doDatafixers = true; + @Configurable @Configurable.Comment("Config options regarding GTEU compatibility with other energy systems") public EnergyCompatConfig energy = new EnergyCompatConfig(); @@ -203,6 +241,7 @@ public static class CompatibilityConfigs { @Configurable @Configurable.Comment({ "Whether Create compatibility will be available.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean createCompat = true; public static class EnergyCompatConfig { @@ -214,18 +253,19 @@ public static class EnergyCompatConfig { @Configurable @Configurable.Comment({ "Enable GTEU to FE (and vice versa) Converters.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean enableFEConverters = false; @Configurable @Configurable.Comment({ "Forge Energy to GTEU ratio for converting FE to EU.", "Only affects converters.", "Default: 4 FE == 1 EU" }) - @Configurable.Range(min = 1, max = Integer.MAX_VALUE) + @Configurable.Range(min = 1, max = 16) public int feToEuRatio = 4; @Configurable @Configurable.Comment({ "GTEU to Forge Energy ratio for converting EU to FE.", "Affects native conversion and Converters.", "Default: 4 FE == 1 EU" }) - @Configurable.Range(min = 1, max = Integer.MAX_VALUE) + @Configurable.Range(min = 1, max = 16) public int euToFeRatio = 4; } @@ -240,6 +280,7 @@ public static class AE2CompatConfig { @Configurable @Configurable.Comment({ "The energy consumption of ME Hatch/Bus.", "Default: 4.0AE/t" }) @Configurable.DecimalRange(min = 0.0, max = Integer.MAX_VALUE) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public double meHatchEnergyUsage = 4.0; } @@ -247,18 +288,19 @@ public static class MinimapCompatConfig { @Configurable @Configurable.Comment({ - "Toggle specific map mod integration on/off (need to restart for this to take effect)" }) + "Toggle specific map mod integration on/off" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public Toggle toggle = new Toggle(); @Configurable @Configurable.Comment({ "The radius, in blocks, that picking up a surface rock will search for veins in.", "-1 to disable.", "Default: 24" }) - @Configurable.Range(min = -1) + @Configurable.Range(min = 1) public int surfaceRockProspectRange = 24; @Configurable @Configurable.Comment({ "The radius, in blocks, that clicking an ore block will search for veins in.", "-1 to disable", "Default: 24" }) - @Configurable.Range(min = -1) + @Configurable.Range(min = 1) public int oreBlockProspectRange = 24; @Configurable @@ -301,14 +343,17 @@ public static class Toggle { @Configurable @Configurable.Comment({ "FTB Chunks integration enabled" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean ftbChunksIntegration = false; @Configurable @Configurable.Comment({ "Journey Map integration enabled" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean journeyMapIntegration = true; @Configurable @Configurable.Comment({ "Xaerox's map integration enabled" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean xaerosMapIntegration = true; } @@ -375,10 +420,12 @@ public static class WorldGenConfigs { @Configurable.Comment({ "Whether to increase number of rolls for dungeon chests. Increases dungeon loot drastically.", "Default: true", "WARNING: Currently unimplemented." }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean increaseDungeonLoot = true; @Configurable @Configurable.Comment({ "Allow GregTech to add additional GregTech Items as loot in various structures.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean addLoot = true; @Configurable @@ -403,9 +450,11 @@ public static class OreVeinConfigs { @Configurable @Configurable.Comment({ "Prevents regular vanilla ores from being generated outside GregTech ore veins", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean removeVanillaOreGen = true; @Configurable @Configurable.Comment({ "Prevents vanilla's large ore veins from being generated", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean removeVanillaLargeOreVeins = true; @Configurable @Configurable.Comment({ "Distance between bedrock ore veins in chunks, if enabled.", "Default: 16" }) @@ -421,15 +470,17 @@ public static class OreVeinConfigs { "Sets the maximum number of chunks that may be cached for ore vein generation.", "Higher values may improve world generation performance, but at the cost of more RAM usage.", "If you substantially increase the ore vein grid size, random vein offset, or have very large (custom) veins, you may need to increase this value as well.", - "Default: 512 (requires restarting the server / re-opening the world)" + "Default: 512" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public int oreGenerationChunkCacheSize = 512; @Configurable @Configurable.Comment({ "Sets the maximum number of chunks for which ore indicators may be cached.", "If you register any custom veins with very large indicator ranges (or modify existing ones that way), you may need to increase this value.", - "Default: 2048 (requires restarting the server / re-opening the world)" + "Default: 2048" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public int oreIndicatorChunkCacheSize = 2048; } } @@ -440,28 +491,34 @@ public static class MachineConfigs { @Configurable.Comment({ "Whether to require a Wrench, Wirecutter, or other GregTech tools to break machines, casings, wires, and more.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean requireGTToolsForBlocks = true; @Configurable @Configurable.Comment({ "Whether machines explode in rainy weather or when placed next to certain terrain, such as fire or lava", "Default: false" }) + @Configurable.Synchronized public boolean shouldWeatherOrTerrainExplosion = false; @Configurable @Configurable.Comment({ "Energy use multiplier for electric items.", "Default: 100" }) + @Configurable.Synchronized public int energyUsageMultiplier = 100; @Configurable @Configurable.Comment({ "Energy use multiplier for prospectors.", "Default: 100" }) + @Configurable.Synchronized public int prospectorEnergyUseMultiplier = 100; @Configurable @Configurable.Comment({ "Whether machines or boilers damage the terrain when they explode.", "Note machines and boilers always explode when overloaded with power or met with special conditions, regardless of this config.", "Default: true" }) + @Configurable.Synchronized public boolean doesExplosionDamagesTerrain = true; @Configurable @Configurable.Comment({ "Enables Safe Active Transformers, removing their ability to explode if unformed while transmitting/receiving power.", "Default: false" }) + @Configurable.Synchronized public boolean harmlessActiveTransformers = false; @Configurable @Configurable.Comment({ "Whether to play machine sounds while machines are active.", "Default: true" }) @@ -471,9 +528,11 @@ public static class MachineConfigs { public int batchDuration = 100; @Configurable @Configurable.Comment({ "Whether Steam Multiblocks should use Steel instead of Bronze.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean steelSteamMultiblocks = false; @Configurable @Configurable.Comment({ "Whether to enable the cleanroom, required for various recipes.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean enableCleanroom = true; @Configurable @Configurable.Comment({ "Whether multiblocks should ignore all cleanroom requirements.", @@ -490,9 +549,11 @@ public static class MachineConfigs { public String replaceMinedBlocksWith = "minecraft:cobblestone"; @Configurable @Configurable.Comment({ "Whether to enable Assembly Line research for recipes.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean enableResearch = true; @Configurable @Configurable.Comment({ "Whether to enable the Maintenance Hatch, required for Multiblocks.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean enableMaintenance = true; @Configurable @Configurable.Comment({ @@ -505,27 +566,32 @@ public static class MachineConfigs { @Configurable.Comment({ "Whether to enable World Accelerators, which accelerate ticks for surrounding Tile Entities, Crops, etc.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean enableWorldAccelerators = true; @Configurable - @Configurable.Comment({ "List of TileEntities that the World Accelerator should not accelerate.", + @Configurable.Comment({ "List of Block entities that the World Accelerator should not accelerate.", "GregTech TileEntities are always blocked.", - "Entries must be in a fully qualified format. For example: appeng.tile.networking.TileController", + "Entries must be in a fully qualified format. For example: ae2:controller", "Default: none" }) - public String[] worldAcceleratorBlacklist = new String[0]; + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) + public ResourceLocation[] worldAcceleratorBlacklist = new ResourceLocation[0]; @Configurable @Configurable.Comment({ "Whether to use GT6-style pipe and cable connections, meaning they will not auto-connect " + "unless placed directly onto another pipe or cable.", "Default: true" }) + @Configurable.Synchronized public boolean gt6StylePipesCables = true; @Configurable @Configurable.Comment({ "Whether the machine's circuit slot need to be inserted a real circuit." }) + @Configurable.Synchronized public boolean ghostCircuit = true; @Configurable @Configurable.Comment({ "Whether to add a \"Bedrock Ore Miner\" (also enables bedrock ore generation)", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean doBedrockOres = false; @Configurable @Configurable.Comment({ "What Kind of material should the bedrock ore miner output?", "Default: \"raw\"" }) @@ -538,24 +604,30 @@ public static class MachineConfigs { @Configurable @Configurable.Comment({ "Makes nearly every GCYM Multiblock require blocks which set their maximum voltages.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) // todo: implement or purge public boolean enableTieredCasings = false; @Configurable @Configurable.Comment({ "Minimum distance between Long Distance Item Pipe Endpoints", "Default: 50" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public int ldItemPipeMinDistance = 50; @Configurable @Configurable.Comment({ "Minimum distance betweeb Long Distance Fluid Pipe Endpoints", "Default: 50" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public int ldFluidPipeMinDistance = 50; @Configurable @Configurable.Comment({ "Whether ONLY owners can open a machine gui", "Default: false" }) + @Configurable.Synchronized public boolean onlyOwnerGUI = false; @Configurable @Configurable.Comment({ "Whether ONLY owners can break a machine", "Default: false" }) + @Configurable.Synchronized public boolean onlyOwnerBreak = false; @Configurable @Configurable.Comment({ "Minimum op level to bypass the ownership checks", "Default: 2" }) @Configurable.Range(min = Commands.LEVEL_ALL, max = Commands.LEVEL_OWNERS) + @Configurable.Synchronized public int ownerOPBypass = Commands.LEVEL_GAMEMASTERS; /** @@ -568,6 +640,7 @@ public static class MachineConfigs { "This is intended for modpack developers only, and is not playable without custom tweaks or addons.", "Other mods can override this to true, regardless of the config file.", "Default: false" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public boolean highTierContent = false; @Configurable @@ -584,6 +657,7 @@ public static class MachineConfigs { "Default maximum parallel of steam multiblocks", "Default: 8" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public int steamMultiParallelAmount = 8; @Configurable @@ -592,9 +666,11 @@ public static class MachineConfigs { @Configurable @Configurable.Comment("Small Steam Boiler Options") + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public SmallBoilers smallBoilers = new SmallBoilers(); @Configurable @Configurable.Comment("Large Steam Boiler Options") + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public LargeBoilers largeBoilers = new LargeBoilers(); public static class SmallBoilers { @@ -680,41 +756,50 @@ public static class ToolConfigs { @Configurable @Configurable.Comment("NightVision Goggles Voltage Tier. Default: 1 (LV)") @Configurable.Range(min = 0, max = 14) - public int voltageTierNightVision = 1; + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) + public int voltageTierNightVision = GTValues.LV; @Configurable @Configurable.Comment("NanoSuit Voltage Tier. Default: 3 (HV)") @Configurable.Range(min = 0, max = 14) - public int voltageTierNanoSuit = 3; + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) + public int voltageTierNanoSuit = GTValues.HV; @Configurable @Configurable.Comment({ "Advanced NanoSuit Chestplate Voltage Tier.", "Default: 3 (HV)" }) @Configurable.Range(min = 0, max = 14) - public int voltageTierAdvNanoSuit = 3; + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) + public int voltageTierAdvNanoSuit = GTValues.HV; @Configurable @Configurable.Comment({ "QuarkTech Suit Voltage Tier.", "Default: 5 (IV)" }) @Configurable.Range(min = 0, max = 14) - public int voltageTierQuarkTech = 5; + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) + public int voltageTierQuarkTech = GTValues.IV; @Configurable @Configurable.Comment({ "Advanced QuarkTech Suit Chestplate Voltage Tier.", "Default: 6 (LuV)" }) @Configurable.Range(min = 0, max = 14) - public int voltageTierAdvQuarkTech = 6; + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) + public int voltageTierAdvQuarkTech = GTValues.LuV; @Configurable @Configurable.Comment({ "Electric Impeller Jetpack Voltage Tier.", "Default: 2 (MV)" }) @Configurable.Range(min = 0, max = 14) - public int voltageTierImpeller = 2; + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) + public int voltageTierImpeller = GTValues.MV; @Configurable @Configurable.Comment({ "Advanced Electric Jetpack Voltage Tier.", "Default: 3 (HV)" }) @Configurable.Range(min = 0, max = 14) - public int voltageTierAdvImpeller = 3; + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) + public int voltageTierAdvImpeller = GTValues.HV; public static class NanoSaber { @Configurable @Configurable.DecimalRange(min = 0, max = 100) @Configurable.Comment({ "The additional damage added when the NanoSaber is powered.", "Default: 20.0" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public double nanoSaberDamageBoost = 20; @Configurable @Configurable.DecimalRange(min = 0, max = 100) @Configurable.Comment({ "The base damage of the NanoSaber.", "Default: 5.0" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public double nanoSaberBaseDamage = 5; @Configurable @Configurable.Comment({ "Should Zombies spawn with charged, active NanoSabers on hard difficulty?", @@ -723,6 +808,7 @@ public static class NanoSaber { @Configurable @Configurable.Range(min = 1, max = 512) @Configurable.Comment({ "The EU/t consumption of the NanoSaber.", "Default: 64" }) + @Configurable.UpdateRestriction(UpdateRestrictions.GAME_RESTART) public int energyConsumption = 64; } } @@ -731,14 +817,17 @@ public static class GameplayConfigs { @Configurable @Configurable.Comment({ "Enable hazardous materials", "Default: true" }) + @Configurable.Synchronized public boolean hazardsEnabled = true; @Configurable @Configurable.Comment({ "Whether hazards are applied to all valid items, or just GT's.", "true = all, false = GT only.", "Default: true" }) + @Configurable.Synchronized public boolean universalHazards = true; @Configurable @Configurable.Comment({ "Whether environmental hazards like pollution or radiation are active", "Default: false" }) + @Configurable.Synchronized public boolean environmentalHazards = false; @Configurable @Configurable.Comment({ "How much environmental hazards decay per chunk, per tick.", @@ -746,6 +835,7 @@ public static class GameplayConfigs { public float environmentalHazardDecayRate = 0.001f; @Configurable @Configurable.Comment({ "List of domains that are allowed in the image module" }) + @Configurable.Synchronized public String[] allowedImageDomains = new String[] { "imgur.com", "discord.com", "github.com", "raw.githubusercontent.com" }; } @@ -787,6 +877,7 @@ public static class ClientConfigs { @Configurable @Configurable.Comment({ "Use VBO cache for multiblock preview.", "Disable if you have issues with rendering multiblocks.", "Default: true" }) + @Configurable.UpdateRestriction(UpdateRestrictions.MAIN_MENU) public boolean useVBO = true; @Configurable @Configurable.Comment({ "Duration of the multiblock in-world preview (s)", "Default: 10" }) @@ -887,4 +978,4 @@ public static class DeveloperConfigs { "Only works in a development environment", "Default: false" }) public boolean autoRebuildResources = false; } -} +} \ No newline at end of file From ec2ccedc32a4eb884d54897baba4b60586e1240b Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:22:59 +0300 Subject: [PATCH 08/17] Fix CommonInit reverts that shouldn't have been reverted --- .../gregtechceu/gtceu/common/CommonProxy.java | 12 +++++++++- .../gtceu/common/data/GTReferences.java | 23 ++++++++++++++++++ .../common/data/GTValueProviderTypes.java | 24 +++++++++---------- 3 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/gregtechceu/gtceu/common/data/GTReferences.java diff --git a/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java b/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java index 1c7e875de22..944b3e35c47 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java +++ b/src/main/java/com/gregtechceu/gtceu/common/CommonProxy.java @@ -50,6 +50,7 @@ import com.gregtechceu.gtceu.common.data.item.*; import com.gregtechceu.gtceu.common.data.machines.GTMachineUtils; import com.gregtechceu.gtceu.common.data.materials.GTFoods; +import com.gregtechceu.gtceu.common.datafixer.GTDataFixers; import com.gregtechceu.gtceu.common.fluid.potion.BottleItemFluidHandler; import com.gregtechceu.gtceu.common.fluid.potion.PotionItemFluidHandler; import com.gregtechceu.gtceu.common.item.DrumMachineItem; @@ -69,7 +70,9 @@ import com.gregtechceu.gtceu.data.pack.GTPackSource; import com.gregtechceu.gtceu.data.placeholder.GTPlaceholders; import com.gregtechceu.gtceu.data.recipe.*; +import com.gregtechceu.gtceu.integration.ae2.GTAEPlaceholders; import com.gregtechceu.gtceu.integration.cctweaked.CCTweakedPlugin; +import com.gregtechceu.gtceu.integration.create.GTCreateIntegration; import com.gregtechceu.gtceu.integration.kjs.GTCEuStartupEvents; import com.gregtechceu.gtceu.integration.kjs.GTKubeJSPlugin; import com.gregtechceu.gtceu.integration.kjs.events.MaterialModificationEventJS; @@ -181,7 +184,14 @@ public static void onRegister(RegisterEvent event) { GTSoundEntries.init(); GTDamageTypes.init(); + GTPlaceholders.initPlaceholders(); + if (GTCEu.Mods.isCreateLoaded()) { + GTCreateIntegration.init(); + } + if (GTCEu.Mods.isAE2Loaded()) { + GTAEPlaceholders.init(); + } GTBlocks.init(); GTFluids.init(); @@ -214,7 +224,7 @@ public static void onRegister(RegisterEvent event) { GTParticleTypes.PARTICLE_TYPES.register(modBus); GregTechDatagen.initPost(); - GTValueProviderTypes.init(modBus); + GTValueProviderTypes.register(modBus); GTFeatures.register(modBus); WorldGenLayers.registerAll(); VeinGenerators.registerAddonGenerators(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTReferences.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTReferences.java new file mode 100644 index 00000000000..8d41f8704ea --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTReferences.java @@ -0,0 +1,23 @@ +package com.gregtechceu.gtceu.common.data; + +import com.mojang.datafixers.DSL; + +public class GTReferences { + + public static final DSL.TypeReference MATERIAL_NAME = reference("material_name"); + + public static DSL.TypeReference reference(final String pName) { + return new DSL.TypeReference() { + + @Override + public String typeName() { + return pName; + } + + @Override + public String toString() { + return "@" + pName; + } + }; + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTValueProviderTypes.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTValueProviderTypes.java index 9535df0c1d5..fdc5de09b3b 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTValueProviderTypes.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTValueProviderTypes.java @@ -15,32 +15,30 @@ public class GTValueProviderTypes { - public static final DeferredRegister> INT_PROVIDER_TYPE_REGISTER = DeferredRegister.create( - Registries.INT_PROVIDER_TYPE, - GTCEu.MOD_ID); - public static final DeferredRegister> FLOAT_PROVIDER_TYPE_REGISTER = DeferredRegister.create( - Registries.FLOAT_PROVIDER_TYPE, - GTCEu.MOD_ID); + public static final DeferredRegister> INT_PROVIDER_TYPES = DeferredRegister + .create(Registries.INT_PROVIDER_TYPE, GTCEu.MOD_ID); + public static final DeferredRegister> FLOAT_PROVIDER_TYPES = DeferredRegister + .create(Registries.FLOAT_PROVIDER_TYPE, GTCEu.MOD_ID); - public static final DeferredHolder, IntProviderType> FLOORED = INT_PROVIDER_TYPE_REGISTER + public static final DeferredHolder, IntProviderType> FLOORED = INT_PROVIDER_TYPES .register( "floored", () -> () -> FlooredInt.CODEC); - public static final DeferredHolder, FloatProviderType> MULTIPLIED = FLOAT_PROVIDER_TYPE_REGISTER + public static final DeferredHolder, FloatProviderType> MULTIPLIED = FLOAT_PROVIDER_TYPES .register("multiplied", () -> () -> MultipliedFloat.CODEC); - public static final DeferredHolder, FloatProviderType> ADDED = FLOAT_PROVIDER_TYPE_REGISTER + public static final DeferredHolder, FloatProviderType> ADDED = FLOAT_PROVIDER_TYPES .register( "added", () -> () -> AddedFloat.CODEC); - public static final DeferredHolder, FloatProviderType> CASTED = FLOAT_PROVIDER_TYPE_REGISTER + public static final DeferredHolder, FloatProviderType> CASTED = FLOAT_PROVIDER_TYPES .register( "casted", () -> () -> CastedFloat.CODEC); - public static void init(IEventBus bus) { - INT_PROVIDER_TYPE_REGISTER.register(bus); - FLOAT_PROVIDER_TYPE_REGISTER.register(bus); + public static void register(IEventBus bus) { + INT_PROVIDER_TYPES.register(bus); + FLOAT_PROVIDER_TYPES.register(bus); } } From 151bfd3de59aa658144a8ece4c466078273b78d6 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:23:30 +0300 Subject: [PATCH 09/17] Fix forge.versions.toml --- gradle/forge.versions.toml | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/gradle/forge.versions.toml b/gradle/forge.versions.toml index 6aa3277de15..a681c5203d8 100644 --- a/gradle/forge.versions.toml +++ b/gradle/forge.versions.toml @@ -6,32 +6,37 @@ configuration = "3.1.1-neoforge" jei = "19.25.1.328" rei = "16.0.799" emi = "1.1.22+1.21.1" + ae2 = "19.2.8" + kubejs = "2101.7.2-build.336" rhino = "2101.2.7-build.81" architectury = "13.0.8" clothconfig = "15.0.140" -create = "6.0.8-168" -ponder = "1.0.64" -flywheel = "1.0.5" + curios = "9.4.2+1.21.1" kotlinforforge = "5.7.0" + journeyMapApi = "2.0.0-1.21.1-SNAPSHOT" ftblibrary = "2101.1.30" ftbteams = "2101.1.9" ftbquests = "2101.1.21" ftbchunks = "2101.1.14" -ccTweaked = "1.116.0" -resourcefullib = "3.0.12" + gamestages = "17.0.1" bookshelf = "21.1.56" + +ccTweaked = "1.116.0" + +resourcefullib = "3.0.12" # TODO update these once there's 1.21 versions argonauts = "1.2.4" # FIXME for some reason their maven only has versions up to 1.1.10? latest on modrinth is 1.1.13 heracles = "1.1.10" -create = "6.0.7-115" -ponder = "1.0.61" -flywheel = "1.0.4-27" + +create = "6.0.8-168" +ponder = "1.0.64" +flywheel = "1.0.5" ## modrinth maven ## jade = "15.10.0+neoforge" @@ -65,16 +70,15 @@ rei-neoforge = { module = "me.shedaniel:RoughlyEnoughItems-neoforge", ver emi = { module = "dev.emi:emi-neoforge", version.ref = "emi" } ae2 = { module = "org.appliedenergistics:appliedenergistics2", version.ref = "ae2" } + kubejs = { module = "dev.latvian.mods:kubejs-neoforge", version.ref = "kubejs" } rhino = { module = "dev.latvian.mods:rhino", version.ref = "rhino" } architectury = { module = "dev.architectury:architectury-neoforge", version.ref = "architectury" } clothconfig = { module = "me.shedaniel.cloth:cloth-config-neoforge", version.ref = "clothconfig" } -create = { module = "com.simibubi.create:create-1.21.1", version.ref = "create" } -ponder = { module = "net.createmod.ponder:Ponder-NeoForge-1.21.1", version.ref = "ponder"} -flywheel-forge-api = { module = "dev.engine-room.flywheel:flywheel-neoforge-api-1.21.1", version.ref = "flywheel"} -flywheel-forge = { module = "dev.engine-room.flywheel:flywheel-neoforge-1.21.1", version.ref = "flywheel"} + curios = { module = "top.theillusivec4.curios:curios-neoforge", version.ref = "curios" } kotlinforforge = { module = "thedarkcolour:kotlinforforge-neoforge", version.ref = "kotlinforforge" } + journeymap-api = { module = "info.journeymap:journeymap-api-neoforge", version.ref = "journeyMapApi" } ftblibrary = { module = "dev.ftb.mods:ftb-library-neoforge", version.ref = "ftblibrary" } ftbteams = { module = "dev.ftb.mods:ftb-teams-neoforge", version.ref = "ftbteams" } From 7f721e88f9239f8b140db15627f7b8f45d1490a8 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:26:47 +0300 Subject: [PATCH 10/17] Fix all these files that were still impossible to merge --- .../com/gregtechceu/gtceu/api/GTValues.java | 3 +- .../event/RegisterDynamicResourcesEvent.java | 2 +- .../item/datacomponents/FacadeWrapper.java | 25 --- .../AutoStockingFancyConfigurator.java | 2 +- .../property/GTMachineModelProperties.java | 2 +- .../CraftingComponentModificationEvent.java | 2 +- .../gregtechceu/gtceu/client/ClientProxy.java | 2 +- .../item/behavior/DataItemBehavior.java | 18 +- .../item/behavior/FacadeItemBehaviour.java | 1 - .../electric/CentralMonitorMachine.java | 4 +- .../core/mixins/client/ModelManagerMixin.java | 2 +- .../data/datagen/lang/ConfigurationLang.java | 34 ---- .../gtceu/data/lang/ConfigurationLang.java | 31 ++-- .../data/recipe/GTCraftingComponents.java | 2 +- .../top/provider/RecipeOutputProvider.java | 158 ------------------ 15 files changed, 30 insertions(+), 258 deletions(-) rename src/main/java/com/gregtechceu/gtceu/{ => api}/data/pack/event/RegisterDynamicResourcesEvent.java (84%) delete mode 100644 src/main/java/com/gregtechceu/gtceu/api/item/datacomponents/FacadeWrapper.java rename src/main/java/com/gregtechceu/gtceu/{data => api}/recipe/event/CraftingComponentModificationEvent.java (82%) delete mode 100644 src/main/java/com/gregtechceu/gtceu/data/datagen/lang/ConfigurationLang.java delete mode 100644 src/main/java/com/gregtechceu/gtceu/integration/top/provider/RecipeOutputProvider.java diff --git a/src/main/java/com/gregtechceu/gtceu/api/GTValues.java b/src/main/java/com/gregtechceu/gtceu/api/GTValues.java index 8c34e3dd61f..184e4860c33 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/GTValues.java +++ b/src/main/java/com/gregtechceu/gtceu/api/GTValues.java @@ -134,8 +134,7 @@ public static int[] tiersBetween(int minInclusive, int maxInclusive) { MODID_HERACLES = "heracles", MODID_GAMESTAGES = "gamestages", MODID_FTB_QUEST = "ftbquests", - MODID_CCTWEAKED = "computercraft", - MODID_CREATE = "create"; + MODID_CCTWEAKED = "computercraft"; /** * Spray painting compat modids diff --git a/src/main/java/com/gregtechceu/gtceu/data/pack/event/RegisterDynamicResourcesEvent.java b/src/main/java/com/gregtechceu/gtceu/api/data/pack/event/RegisterDynamicResourcesEvent.java similarity index 84% rename from src/main/java/com/gregtechceu/gtceu/data/pack/event/RegisterDynamicResourcesEvent.java rename to src/main/java/com/gregtechceu/gtceu/api/data/pack/event/RegisterDynamicResourcesEvent.java index 26dd884312f..4b866b5f786 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/pack/event/RegisterDynamicResourcesEvent.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/pack/event/RegisterDynamicResourcesEvent.java @@ -1,4 +1,4 @@ -package com.gregtechceu.gtceu.data.pack.event; +package com.gregtechceu.gtceu.api.data.pack.event; import net.neoforged.bus.api.Event; import net.neoforged.fml.event.IModBusEvent; diff --git a/src/main/java/com/gregtechceu/gtceu/api/item/datacomponents/FacadeWrapper.java b/src/main/java/com/gregtechceu/gtceu/api/item/datacomponents/FacadeWrapper.java deleted file mode 100644 index d0c8b846254..00000000000 --- a/src/main/java/com/gregtechceu/gtceu/api/item/datacomponents/FacadeWrapper.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.gregtechceu.gtceu.api.item.datacomponents; - -import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.codec.ByteBufCodecs; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.world.level.block.state.BlockState; - -import com.mojang.serialization.Codec; - -public record FacadeWrapper(BlockState state) { - - public static final Codec CODEC = BlockState.CODEC.xmap(FacadeWrapper::new, FacadeWrapper::state); - public static final StreamCodec STREAM_CODEC = ByteBufCodecs - .fromCodecWithRegistries(CODEC); - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof FacadeWrapper(BlockState thatState))) - return false; - - return state == thatState; - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/AutoStockingFancyConfigurator.java b/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/AutoStockingFancyConfigurator.java index 0b6e3c3b1d7..40b203f409c 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/AutoStockingFancyConfigurator.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/fancyconfigurator/AutoStockingFancyConfigurator.java @@ -2,8 +2,8 @@ import com.gregtechceu.gtceu.api.gui.fancy.IFancyConfigurator; import com.gregtechceu.gtceu.api.gui.widget.IntInputWidget; +import com.gregtechceu.gtceu.common.data.GTItems; import com.gregtechceu.gtceu.config.ConfigHolder; -import com.gregtechceu.gtceu.data.item.GTItems; import com.gregtechceu.gtceu.integration.ae2.machine.MEStockingBusPartMachine; import com.gregtechceu.gtceu.integration.ae2.machine.feature.multiblock.IMEStockingPart; diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/property/GTMachineModelProperties.java b/src/main/java/com/gregtechceu/gtceu/api/machine/property/GTMachineModelProperties.java index 883e9b7b82b..b88a0b1e93a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/property/GTMachineModelProperties.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/property/GTMachineModelProperties.java @@ -1,7 +1,7 @@ package com.gregtechceu.gtceu.api.machine.property; import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic; -import com.gregtechceu.gtceu.api.multiblock.util.RelativeDirection; +import com.gregtechceu.gtceu.api.pattern.util.RelativeDirection; import com.gregtechceu.gtceu.common.machine.electric.ChargerMachine; import com.gregtechceu.gtceu.common.machine.multiblock.part.DiodePartMachine; diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/event/CraftingComponentModificationEvent.java b/src/main/java/com/gregtechceu/gtceu/api/recipe/event/CraftingComponentModificationEvent.java similarity index 82% rename from src/main/java/com/gregtechceu/gtceu/data/recipe/event/CraftingComponentModificationEvent.java rename to src/main/java/com/gregtechceu/gtceu/api/recipe/event/CraftingComponentModificationEvent.java index bd7af5cce79..1bbe26db74a 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/event/CraftingComponentModificationEvent.java +++ b/src/main/java/com/gregtechceu/gtceu/api/recipe/event/CraftingComponentModificationEvent.java @@ -1,4 +1,4 @@ -package com.gregtechceu.gtceu.data.recipe.event; +package com.gregtechceu.gtceu.api.recipe.event; import net.neoforged.bus.api.Event; diff --git a/src/main/java/com/gregtechceu/gtceu/client/ClientProxy.java b/src/main/java/com/gregtechceu/gtceu/client/ClientProxy.java index 2385f0cf29e..072b3c2b258 100644 --- a/src/main/java/com/gregtechceu/gtceu/client/ClientProxy.java +++ b/src/main/java/com/gregtechceu/gtceu/client/ClientProxy.java @@ -3,6 +3,7 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.GTValues; import com.gregtechceu.gtceu.api.cosmetics.event.RegisterGTCapesEvent; +import com.gregtechceu.gtceu.api.data.pack.event.RegisterDynamicResourcesEvent; import com.gregtechceu.gtceu.api.item.IComponentItem; import com.gregtechceu.gtceu.api.item.IGTTool; import com.gregtechceu.gtceu.client.model.item.FacadeUnbakedModel; @@ -36,7 +37,6 @@ import com.gregtechceu.gtceu.common.item.QuantumTankMachineItem; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.data.model.builder.PipeModelBuilder; -import com.gregtechceu.gtceu.data.pack.event.RegisterDynamicResourcesEvent; import com.gregtechceu.gtceu.integration.kjs.GTKubeJSPlugin; import com.gregtechceu.gtceu.integration.map.ClientCacheManager; import com.gregtechceu.gtceu.integration.map.cache.client.GTClientCache; diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/behavior/DataItemBehavior.java b/src/main/java/com/gregtechceu/gtceu/common/item/behavior/DataItemBehavior.java index 33f2d112793..b500374a527 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/behavior/DataItemBehavior.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/behavior/DataItemBehavior.java @@ -1,6 +1,5 @@ package com.gregtechceu.gtceu.common.item.behavior; -import com.gregtechceu.gtceu.api.blockentity.MetaMachineBlockEntity; import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper; import com.gregtechceu.gtceu.api.capability.ICoverable; import com.gregtechceu.gtceu.api.item.component.IInteractionItem; @@ -9,7 +8,10 @@ import com.gregtechceu.gtceu.common.data.item.GTDataComponents; import com.gregtechceu.gtceu.common.item.datacomponents.BindingData; import com.gregtechceu.gtceu.common.machine.owner.MachineOwner; +import com.gregtechceu.gtceu.core.mixins.EntityAccessor; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; @@ -36,20 +38,6 @@ public InteractionResultHolder use(ItemStack stack, Level level, return IInteractionItem.super.use(stack, level, player, usedHand); } - @Override - public InteractionResultHolder use(ItemStack item, Level level, Player player, - InteractionHand usedHand) { - if (player.isShiftKeyDown()) { - ItemStack stack = player.getItemInHand(usedHand); - int permissionLevel = 0; - while (player.hasPermissions(permissionLevel)) permissionLevel++; - - stack.set(GTDataComponents.BINDING_DATA, new BindingData(permissionLevel, player.getUUID())); - return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack); - } - return IInteractionItem.super.use(item, level, player, usedHand); - } - @Override public InteractionResult onItemUseFirst(ItemStack itemStack, UseOnContext context) { Level level = context.getLevel(); diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/behavior/FacadeItemBehaviour.java b/src/main/java/com/gregtechceu/gtceu/common/item/behavior/FacadeItemBehaviour.java index 3a731f8d550..59a880fbd23 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/behavior/FacadeItemBehaviour.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/behavior/FacadeItemBehaviour.java @@ -2,7 +2,6 @@ import com.gregtechceu.gtceu.api.item.component.ICustomDescriptionId; import com.gregtechceu.gtceu.api.item.component.ISubItemHandler; -import com.gregtechceu.gtceu.api.item.datacomponents.FacadeWrapper; import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.common.data.item.GTDataComponents; import com.gregtechceu.gtceu.utils.memoization.GTMemoizer; diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CentralMonitorMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CentralMonitorMachine.java index 8d3d21066d5..d28d56439e7 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CentralMonitorMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/CentralMonitorMachine.java @@ -28,7 +28,7 @@ import com.gregtechceu.gtceu.common.machine.multiblock.electric.monitor.MonitorGroup; import com.gregtechceu.gtceu.common.machine.trait.CentralMonitorLogic; import com.gregtechceu.gtceu.common.network.packets.SCPacketMonitorGroupNBTChange; -import com.gregtechceu.gtceu.data.datagen.lang.LangHandler; +import com.gregtechceu.gtceu.data.lang.LangHandler; import com.gregtechceu.gtceu.utils.GTStringUtils; import com.lowdragmc.lowdraglib.gui.texture.*; @@ -604,7 +604,7 @@ public Widget createUIWidget() { return; } else { try { - rightClickCallbacks.get(selectedTargets.getFirst(0).getPos()).run(); + rightClickCallbacks.get(selectedTargets.get(0).getPos()).run(); } catch (StackOverflowError e) { GTCEu.LOGGER.error( "Stack overflow when right-clicking monitor component {} at {} (selectedTarget={}, at {})", diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/client/ModelManagerMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/client/ModelManagerMixin.java index 5ce2c2fa834..b116f6100e4 100644 --- a/src/main/java/com/gregtechceu/gtceu/core/mixins/client/ModelManagerMixin.java +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/client/ModelManagerMixin.java @@ -1,7 +1,7 @@ package com.gregtechceu.gtceu.core.mixins.client; import com.gregtechceu.gtceu.GTCEu; -import com.gregtechceu.gtceu.data.pack.event.RegisterDynamicResourcesEvent; +import com.gregtechceu.gtceu.api.data.pack.event.RegisterDynamicResourcesEvent; import com.gregtechceu.gtceu.integration.modernfix.GTModernFixIntegration; import net.minecraft.client.resources.model.ModelManager; diff --git a/src/main/java/com/gregtechceu/gtceu/data/datagen/lang/ConfigurationLang.java b/src/main/java/com/gregtechceu/gtceu/data/datagen/lang/ConfigurationLang.java deleted file mode 100644 index 186f6f9171b..00000000000 --- a/src/main/java/com/gregtechceu/gtceu/data/datagen/lang/ConfigurationLang.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.gregtechceu.gtceu.data.datagen.lang; - -import com.gregtechceu.gtceu.config.ConfigHolder; - -import com.tterrag.registrate.providers.RegistrateLangProvider; -import dev.toma.configuration.config.value.IConfigValue; -import dev.toma.configuration.config.value.IHierarchical; - -import java.util.HashSet; -import java.util.Set; - -public class ConfigurationLang { - - public static void init(final RegistrateLangProvider provider) { - final Set added = new HashSet<>(); - ConfigHolder.INTERNAL_INSTANCE.values() - .forEach((value) -> addTranslation(provider, added, value)); - } - - private static void addTranslation(RegistrateLangProvider provider, Set added, IConfigValue value) { - var id = value.getId(); - if (added.add(id)) { - provider.add("config.gtceu.option." + id, id); - } - if (value instanceof IHierarchical hierarchical) { - for (String childKey : value.getChildrenKeys()) { - IConfigValue child = hierarchical.getChildById(childKey); - if (child != null) { - addTranslation(provider, added, child); - } - } - } - } -} diff --git a/src/main/java/com/gregtechceu/gtceu/data/lang/ConfigurationLang.java b/src/main/java/com/gregtechceu/gtceu/data/lang/ConfigurationLang.java index 6c355cf0c83..de63da5fa7d 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/lang/ConfigurationLang.java +++ b/src/main/java/com/gregtechceu/gtceu/data/lang/ConfigurationLang.java @@ -1,30 +1,33 @@ package com.gregtechceu.gtceu.data.lang; -import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.config.ConfigHolder; import com.tterrag.registrate.providers.RegistrateLangProvider; -import dev.toma.configuration.config.value.ConfigValue; -import dev.toma.configuration.config.value.ObjectValue; +import dev.toma.configuration.config.value.IConfigValue; +import dev.toma.configuration.config.value.IHierarchical; import java.util.HashSet; -import java.util.Map; import java.util.Set; public class ConfigurationLang { - public static void init(RegistrateLangProvider provider) { - dfs(provider, new HashSet<>(), ConfigHolder.INTERNAL_INSTANCE.getValueMap()); + public static void init(final RegistrateLangProvider provider) { + final Set added = new HashSet<>(); + ConfigHolder.INTERNAL_INSTANCE.values() + .forEach((value) -> addTranslation(provider, added, value)); } - private static void dfs(RegistrateLangProvider provider, Set added, Map> map) { - for (var entry : map.entrySet()) { - var id = entry.getValue().getId(); - if (added.add(id)) { - provider.add(String.format("config.%s.option.%s", GTCEu.MOD_ID, id), id); - } - if (entry.getValue() instanceof ObjectValue objectValue) { - dfs(provider, added, objectValue.get()); + private static void addTranslation(RegistrateLangProvider provider, Set added, IConfigValue value) { + var id = value.getId(); + if (added.add(id)) { + provider.add("config.gtceu.option." + id, id); + } + if (value instanceof IHierarchical hierarchical) { + for (String childKey : value.getChildrenKeys()) { + IConfigValue child = hierarchical.getChildById(childKey); + if (child != null) { + addTranslation(provider, added, child); + } } } } diff --git a/src/main/java/com/gregtechceu/gtceu/data/recipe/GTCraftingComponents.java b/src/main/java/com/gregtechceu/gtceu/data/recipe/GTCraftingComponents.java index b5015a7f873..6ded1eb6c7a 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/recipe/GTCraftingComponents.java +++ b/src/main/java/com/gregtechceu/gtceu/data/recipe/GTCraftingComponents.java @@ -2,10 +2,10 @@ import com.gregtechceu.gtceu.GTCEu; import com.gregtechceu.gtceu.api.GTCEuAPI; +import com.gregtechceu.gtceu.api.recipe.event.CraftingComponentModificationEvent; import com.gregtechceu.gtceu.common.data.GTBlocks; import com.gregtechceu.gtceu.common.data.GTItems; import com.gregtechceu.gtceu.common.data.GTMachines; -import com.gregtechceu.gtceu.data.recipe.event.CraftingComponentModificationEvent; import com.gregtechceu.gtceu.integration.kjs.GTCEuStartupEvents; import com.gregtechceu.gtceu.integration.kjs.events.CraftingComponentsEventJS; diff --git a/src/main/java/com/gregtechceu/gtceu/integration/top/provider/RecipeOutputProvider.java b/src/main/java/com/gregtechceu/gtceu/integration/top/provider/RecipeOutputProvider.java deleted file mode 100644 index beb597f2a7d..00000000000 --- a/src/main/java/com/gregtechceu/gtceu/integration/top/provider/RecipeOutputProvider.java +++ /dev/null @@ -1,158 +0,0 @@ -package com.gregtechceu.gtceu.integration.top.provider; - -import com.gregtechceu.gtceu.GTCEu; -import com.gregtechceu.gtceu.api.capability.GTCapabilityHelper; -import com.gregtechceu.gtceu.api.capability.recipe.FluidRecipeCapability; -import com.gregtechceu.gtceu.api.capability.recipe.ItemRecipeCapability; -import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic; -import com.gregtechceu.gtceu.api.recipe.RecipeHelper; -import com.gregtechceu.gtceu.api.recipe.ingredient.IntProviderFluidIngredient; -import com.gregtechceu.gtceu.api.recipe.ingredient.IntProviderIngredient; -import com.gregtechceu.gtceu.api.recipe.ingredient.SizedIngredientExtensions; -import com.gregtechceu.gtceu.integration.top.element.FluidStackElement; -import com.gregtechceu.gtceu.integration.top.element.FluidStyle; - -import net.minecraft.core.BlockPos; -import net.minecraft.core.Direction; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.neoforged.neoforge.common.crafting.SizedIngredient; -import net.neoforged.neoforge.fluids.FluidStack; -import net.neoforged.neoforge.fluids.crafting.SizedFluidIngredient; - -import lombok.experimental.ExtensionMethod; -import mcjty.theoneprobe.api.CompoundText; -import mcjty.theoneprobe.api.ElementAlignment; -import mcjty.theoneprobe.api.IProbeHitData; -import mcjty.theoneprobe.api.IProbeInfo; -import mcjty.theoneprobe.apiimpl.styles.ItemStyle; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; - -@ExtensionMethod(SizedIngredientExtensions.class) -public class RecipeOutputProvider extends CapabilityInfoProvider { - - @Override - public ResourceLocation getID() { - return GTCEu.id("recipe_output_info"); - } - - @Nullable - @Override - protected RecipeLogic getCapability(Level level, BlockPos blockPos, @Nullable Direction direction) { - return GTCapabilityHelper.getRecipeLogic(level, blockPos, direction); - } - - @Override - protected void addProbeInfo(RecipeLogic recipeLogic, IProbeInfo iProbeInfo, Player player, BlockEntity blockEntity, - IProbeHitData iProbeHitData) { - if (recipeLogic.isWorking()) { - var recipe = recipeLogic.getLastRecipe(); - if (recipe != null) { - int recipeTier = RecipeHelper.getPreOCRecipeEuTier(recipe); - int chanceTier = recipeTier + recipe.ocLevel; - var function = recipe.getType().getChanceFunction(); - var itemContents = recipe.getOutputContents(ItemRecipeCapability.CAP); - var fluidContents = recipe.getOutputContents(FluidRecipeCapability.CAP); - - List itemOutputs = new ArrayList<>(); - for (var item : itemContents) { - var stacks = ItemRecipeCapability.CAP.of(item.content).getItems(); - if (stacks.length == 0) continue; - if (stacks[0].isEmpty()) continue; - var stack = stacks[0].copy(); - - if (item.chance < item.maxChance) { - int count = stack.getCount(); - double countD = (double) count * recipe.parallels * - function.getBoostedChance(item, recipeTier, chanceTier) / item.maxChance; - count = countD < 1 ? 1 : (int) Math.round(countD); - stack.setCount(count); - } - itemOutputs.add(RecipeHelper.makeSizedIngredient(stack)); - } - - List fluidOutputs = new ArrayList<>(); - for (var fluid : fluidContents) { - var stacks = FluidRecipeCapability.CAP.of(fluid.content).getFluids(); - if (stacks.length == 0) continue; - if (stacks[0].isEmpty()) continue; - var stack = stacks[0].copy(); - - if (fluid.chance < fluid.maxChance) { - int amount = stack.getAmount(); - double amountD = (double) amount * recipe.parallels * - function.getBoostedChance(fluid, recipeTier, chanceTier) / fluid.maxChance; - amount = amountD < 1 ? 1 : (int) Math.round(amountD); - stack.setAmount(amount); - } - fluidOutputs.add(RecipeHelper.makeSizedFluidIngredient(stack)); - } - - if (!itemOutputs.isEmpty() || !fluidOutputs.isEmpty()) { - IProbeInfo verticalPane = iProbeInfo.vertical(iProbeInfo.defaultLayoutStyle().spacing(0)); - verticalPane.text( - CompoundText.create().info(Component.translatable("gtceu.top.recipe_output").append(" "))); - addItemInfo(verticalPane, itemOutputs); - addFluidInfo(verticalPane, fluidOutputs); - } - } - } - } - - private void addItemInfo(IProbeInfo verticalPane, List outputItems) { - for (SizedIngredient itemOutput : outputItems) { - if (itemOutput != null && !itemOutput.ingredient().hasNoItems()) { - ItemStack stack = itemOutput.getItems()[0]; - - IProbeInfo horizontalPane = verticalPane - .horizontal(verticalPane.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER)); - MutableComponent spacer = CommonComponents.space(); - - if (itemOutput.getContainedCustom() instanceof IntProviderIngredient provider) { - spacer = spacer.append(Component.translatable("gtceu.gui.content.range", - String.valueOf(provider.getCountProvider().getMinValue()), - String.valueOf(provider.getCountProvider().getMaxValue()))) - .append(CommonComponents.SPACE); - provider.setItemStacks(null); // no roll - provider.setSampledCount(1); - } - horizontalPane.item(stack, - new ItemStyle().width(16).height(16)) - .text(spacer) - .itemLabel(stack); - } - } - } - - private void addFluidInfo(IProbeInfo verticalPane, List outputFluids) { - for (SizedFluidIngredient fluidOutput : outputFluids) { - if (fluidOutput != null && !fluidOutput.ingredient().hasNoFluids()) { - FluidStack stack = fluidOutput.getFluids()[0]; - - IProbeInfo horizontalPane = verticalPane - .horizontal(verticalPane.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER)); - MutableComponent spacer = CommonComponents.space(); - - if (fluidOutput.ingredient() instanceof IntProviderFluidIngredient provider) { - spacer = spacer.append(Component.translatable("gtceu.gui.content.range", - String.valueOf(provider.getCountProvider().getMinValue()), - String.valueOf(provider.getCountProvider().getMaxValue()))) - .append(CommonComponents.SPACE); - stack.setAmount(provider.getCountProvider().getMaxValue()); // no roll - } - horizontalPane.element(new FluidStackElement(stack, new FluidStyle())) - .text(spacer) - .text(stack.getHoverName()); - } - } - } -} From f03215674623012da54c4ce127fd858777f27ff2 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:27:52 +0300 Subject: [PATCH 11/17] Formatting --- .../api/machine/steam/SteamEnergyRecipeHandler.java | 3 ++- .../gtceu/api/registry/registrate/GTRegistrate.java | 5 ----- .../gregtechceu/gtceu/client/model/pipe/PipeModel.java | 3 ++- .../java/com/gregtechceu/gtceu/common/data/GTItems.java | 4 ++-- .../common/network/packets/CPacketImageRequest.java | 3 +++ .../network/packets/SCPacketMonitorGroupNBTChange.java | 9 --------- .../common/network/packets/SPacketImageResponse.java | 2 -- .../java/com/gregtechceu/gtceu/config/ConfigHolder.java | 2 +- .../gtceu/core/mixins/client/LevelRendererMixin.java | 2 -- .../gtceu/data/placeholder/GTPlaceholders.java | 5 +++-- .../gtceu/integration/ae2/GTAEPlaceholders.java | 4 ++-- .../cctweaked/peripherals/CentralMonitorPeripheral.java | 4 ++-- .../java/com/gregtechceu/gtceu/utils/GTStringUtils.java | 8 ++++---- 13 files changed, 21 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamEnergyRecipeHandler.java b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamEnergyRecipeHandler.java index 64c36d9024d..17d760a5aef 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamEnergyRecipeHandler.java +++ b/src/main/java/com/gregtechceu/gtceu/api/machine/steam/SteamEnergyRecipeHandler.java @@ -40,7 +40,8 @@ public List handleRecipeInner(IO io, GTRecipe recipe, List 0) { - SizedFluidIngredient steam = io == IO.IN ? SizedFluidIngredient.of(GTMaterials.Steam.getFluidTag(), totalSteam) : + SizedFluidIngredient steam = io == IO.IN ? + SizedFluidIngredient.of(GTMaterials.Steam.getFluidTag(), totalSteam) : SizedFluidIngredient.of(GTMaterials.Steam.getFluid(totalSteam)); List list = new ArrayList<>(); list.add(steam); diff --git a/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/GTRegistrate.java b/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/GTRegistrate.java index fb16932e103..fa8a55d38b5 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/GTRegistrate.java +++ b/src/main/java/com/gregtechceu/gtceu/api/registry/registrate/GTRegistrate.java @@ -52,7 +52,6 @@ import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; -import java.util.function.Supplier; public class GTRegistrate extends AbstractRegistrate { @@ -242,10 +241,6 @@ public GTBlockBuilder block(P parent, String name, return this.currentTab; } - public void creativeModeTab(Supplier> currentTab) { - this.currentTab = currentTab.get(); - } - public void resetCreativeModeTab() { this.currentTab = null; } diff --git a/src/main/java/com/gregtechceu/gtceu/client/model/pipe/PipeModel.java b/src/main/java/com/gregtechceu/gtceu/client/model/pipe/PipeModel.java index aa80c3583e5..6e73948b11e 100644 --- a/src/main/java/com/gregtechceu/gtceu/client/model/pipe/PipeModel.java +++ b/src/main/java/com/gregtechceu/gtceu/client/model/pipe/PipeModel.java @@ -1,10 +1,11 @@ package com.gregtechceu.gtceu.client.model.pipe; import com.gregtechceu.gtceu.api.block.PipeBlock; +import com.gregtechceu.gtceu.api.data.pack.event.RegisterDynamicResourcesEvent; import com.gregtechceu.gtceu.api.registry.registrate.GTBlockBuilder; import com.gregtechceu.gtceu.api.registry.registrate.provider.GTBlockstateProvider; +import com.gregtechceu.gtceu.common.data.GTBlockStateProperties; import com.gregtechceu.gtceu.data.model.builder.PipeModelBuilder; -import com.gregtechceu.gtceu.data.pack.event.RegisterDynamicResourcesEvent; import com.gregtechceu.gtceu.utils.GTMath; import com.gregtechceu.gtceu.utils.GTUtil; diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java index 5e0ed3fecb9..f47fac11c2d 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTItems.java @@ -27,9 +27,9 @@ import com.gregtechceu.gtceu.common.item.armor.GTArmorMaterials; import com.gregtechceu.gtceu.common.item.behavior.*; import com.gregtechceu.gtceu.common.item.behavior.MachineConfigCopyBehaviour; +import com.gregtechceu.gtceu.common.item.behavior.modules.ImageModuleBehaviour; +import com.gregtechceu.gtceu.common.item.behavior.modules.TextModuleBehaviour; import com.gregtechceu.gtceu.common.item.datacomponents.DataItem; -import com.gregtechceu.gtceu.common.item.modules.ImageModuleBehaviour; -import com.gregtechceu.gtceu.common.item.modules.TextModuleBehaviour; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.data.lang.LangHandler; import com.gregtechceu.gtceu.data.recipe.CustomTags; diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketImageRequest.java b/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketImageRequest.java index e6a1077a416..e10d66334a6 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketImageRequest.java +++ b/src/main/java/com/gregtechceu/gtceu/common/network/packets/CPacketImageRequest.java @@ -9,6 +9,9 @@ import net.minecraft.resources.ResourceLocation; import net.neoforged.neoforge.network.handling.IPayloadContext; +import io.netty.buffer.ByteBuf; +import lombok.AccessLevel; +import lombok.Getter; import org.jetbrains.annotations.NotNull; import java.io.IOException; diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SCPacketMonitorGroupNBTChange.java b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SCPacketMonitorGroupNBTChange.java index 855fc501bda..35ced335855 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SCPacketMonitorGroupNBTChange.java +++ b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SCPacketMonitorGroupNBTChange.java @@ -7,24 +7,15 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.RegistryFriendlyByteBuf; -import net.minecraft.network.codec.StreamCodec; -import net.minecraft.network.protocol.common.custom.CustomPacketPayload; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.network.RegistryFriendlyByteBuf; import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; -import net.neoforged.neoforge.common.util.LogicalSidedProvider; import net.neoforged.neoforge.items.IItemHandlerModifiable; import net.neoforged.neoforge.network.handling.IPayloadContext; -import org.jetbrains.annotations.NotNull; -import net.neoforged.neoforge.network.handling.IPayloadContext; - import lombok.AccessLevel; import lombok.Getter; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketImageResponse.java b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketImageResponse.java index 1a5d8a73772..203490666e8 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketImageResponse.java +++ b/src/main/java/com/gregtechceu/gtceu/common/network/packets/SPacketImageResponse.java @@ -13,13 +13,11 @@ import io.netty.buffer.ByteBuf; import lombok.AccessLevel; import lombok.Getter; -import lombok.experimental.Accessors; import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; import java.io.IOException; -@Accessors public class SPacketImageResponse implements CustomPacketPayload { public static final ResourceLocation ID = GTCEu.id("image_response"); diff --git a/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java b/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java index 425d69dd673..cf96bb5f84f 100644 --- a/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java +++ b/src/main/java/com/gregtechceu/gtceu/config/ConfigHolder.java @@ -978,4 +978,4 @@ public static class DeveloperConfigs { "Only works in a development environment", "Default: false" }) public boolean autoRebuildResources = false; } -} \ No newline at end of file +} diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/client/LevelRendererMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/client/LevelRendererMixin.java index 2a85af92007..b66140a3c88 100644 --- a/src/main/java/com/gregtechceu/gtceu/core/mixins/client/LevelRendererMixin.java +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/client/LevelRendererMixin.java @@ -10,8 +10,6 @@ import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; import com.gregtechceu.gtceu.api.machine.feature.ITieredMachine; import com.gregtechceu.gtceu.api.machine.steam.SteamMachine; -import com.gregtechceu.gtceu.api.material.ChemicalHelper; -import com.gregtechceu.gtceu.api.material.material.stack.MaterialEntry; import com.gregtechceu.gtceu.api.pipenet.IPipeNode; import com.gregtechceu.gtceu.common.blockentity.CableBlockEntity; import com.gregtechceu.gtceu.config.ConfigHolder; diff --git a/src/main/java/com/gregtechceu/gtceu/data/placeholder/GTPlaceholders.java b/src/main/java/com/gregtechceu/gtceu/data/placeholder/GTPlaceholders.java index 8d7028c9a89..0cd535968b6 100644 --- a/src/main/java/com/gregtechceu/gtceu/data/placeholder/GTPlaceholders.java +++ b/src/main/java/com/gregtechceu/gtceu/data/placeholder/GTPlaceholders.java @@ -22,10 +22,10 @@ import com.gregtechceu.gtceu.client.renderer.placeholder.RectPlaceholderRenderer; import com.gregtechceu.gtceu.common.blockentity.CableBlockEntity; import com.gregtechceu.gtceu.common.data.item.GTDataComponents; +import com.gregtechceu.gtceu.common.item.behavior.modules.ImageModuleBehaviour; import com.gregtechceu.gtceu.common.item.datacomponents.BindingData; import com.gregtechceu.gtceu.common.item.datacomponents.DataItem; import com.gregtechceu.gtceu.common.item.datacomponents.FormatStringList; -import com.gregtechceu.gtceu.common.item.modules.ImageModuleBehaviour; import com.gregtechceu.gtceu.common.machine.multiblock.part.monitor.AdvancedMonitorPartMachine; import com.gregtechceu.gtceu.config.ConfigHolder; import com.gregtechceu.gtceu.integration.ae2.GTAEPlaceholders; @@ -504,7 +504,8 @@ public MultiLineComponent apply(PlaceholderContext ctx, int slot = GTStringUtils.toInt(args.getFirst()); PlaceholderUtils.checkRange("slot index", 1, ctx.itemHandler().getSlots(), slot); - return MultiLineComponent.literal(ctx.itemHandler().getStackInSlot(slot - 1).getComponents().toString()); + return MultiLineComponent + .literal(ctx.itemHandler().getStackInSlot(slot - 1).getComponents().toString()); } }); PlaceholderHandler.addPlaceholder(new Placeholder("toChars") { diff --git a/src/main/java/com/gregtechceu/gtceu/integration/ae2/GTAEPlaceholders.java b/src/main/java/com/gregtechceu/gtceu/integration/ae2/GTAEPlaceholders.java index eba2256c4ac..4c4569521ad 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/ae2/GTAEPlaceholders.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/ae2/GTAEPlaceholders.java @@ -12,8 +12,8 @@ import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; -import net.minecraft.world.item.Items; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.Fluids; @@ -224,7 +224,7 @@ else if (GTStringUtils.equals(args.get(2), "threads")) else if (GTStringUtils.equals(args.get(2), "name")) return MultiLineComponent .of(cpu.getName() == null ? Component.literal("Crafting CPU " + i) : - cpu.getName().copy()); + cpu.getName()); else if (GTStringUtils.equals(args.get(2), "selectionMode")) return MultiLineComponent.literal(cpu.getSelectionMode().name()); else if (job == null) return MultiLineComponent.literal(0); diff --git a/src/main/java/com/gregtechceu/gtceu/integration/cctweaked/peripherals/CentralMonitorPeripheral.java b/src/main/java/com/gregtechceu/gtceu/integration/cctweaked/peripherals/CentralMonitorPeripheral.java index 5b20d658ca3..4182c6aea57 100644 --- a/src/main/java/com/gregtechceu/gtceu/integration/cctweaked/peripherals/CentralMonitorPeripheral.java +++ b/src/main/java/com/gregtechceu/gtceu/integration/cctweaked/peripherals/CentralMonitorPeripheral.java @@ -4,8 +4,8 @@ import com.gregtechceu.gtceu.api.item.ComponentItem; import com.gregtechceu.gtceu.api.item.component.IItemComponent; import com.gregtechceu.gtceu.api.item.component.IMonitorModuleItem; -import com.gregtechceu.gtceu.common.item.modules.ImageModuleBehaviour; -import com.gregtechceu.gtceu.common.item.modules.TextModuleBehaviour; +import com.gregtechceu.gtceu.common.item.behavior.modules.ImageModuleBehaviour; +import com.gregtechceu.gtceu.common.item.behavior.modules.TextModuleBehaviour; import com.gregtechceu.gtceu.common.machine.multiblock.electric.monitor.MonitorGroup; import net.minecraft.world.item.ItemStack; diff --git a/src/main/java/com/gregtechceu/gtceu/utils/GTStringUtils.java b/src/main/java/com/gregtechceu/gtceu/utils/GTStringUtils.java index c4dffbc7ec2..09cf14fa9c8 100644 --- a/src/main/java/com/gregtechceu/gtceu/utils/GTStringUtils.java +++ b/src/main/java/com/gregtechceu/gtceu/utils/GTStringUtils.java @@ -200,26 +200,26 @@ public static String replace(String s, String regex, List replacements) } public static Component toComponent(ListTag arr) { - return toComponent(List.of(arr.toArray(new String[0]))); + return toComponent(List.of(arr.toArray(String[]::new))); } public static Component toComponent(List arr) { MutableComponent component = Component.literal("["); if (arr.size() <= 5) { for (int i = 0; i < arr.size(); i++) { - component.append(Component.literal('"' + arr.getString(i) + '"').withStyle(ChatFormatting.DARK_AQUA)); + component.append(Component.literal('"' + arr.get(i) + '"').withStyle(ChatFormatting.DARK_AQUA)); if (i != arr.size() - 1) { component.append(ComponentUtils.DEFAULT_NO_STYLE_SEPARATOR); } } } else { for (int i = 0; i < 2; i++) { - component.append(Component.literal('"' + arr.getString(i) + '"').withStyle(ChatFormatting.DARK_AQUA)); + component.append(Component.literal('"' + arr.get(i) + '"').withStyle(ChatFormatting.DARK_AQUA)); component.append(ComponentUtils.DEFAULT_NO_STYLE_SEPARATOR); } component.append(CommonComponents.ELLIPSIS).append(ComponentUtils.DEFAULT_NO_STYLE_SEPARATOR); for (int i = arr.size() - 2; i < arr.size(); i++) { - component.append(Component.literal('"' + arr.getString(i) + '"').withStyle(ChatFormatting.DARK_AQUA)); + component.append(Component.literal('"' + arr.get(i) + '"').withStyle(ChatFormatting.DARK_AQUA)); if (i != arr.size() - 1) { component.append(ComponentUtils.DEFAULT_NO_STYLE_SEPARATOR); } From 815aa24699f200b1f3c9e41d790fd87570401a9f Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:28:26 +0300 Subject: [PATCH 12/17] Fix ResourceLocationMixin having disappeared from the mixin JSON --- src/main/resources/gtceu.mixins.json | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/gtceu.mixins.json b/src/main/resources/gtceu.mixins.json index eec35a59336..9b955e2b2f5 100644 --- a/src/main/resources/gtceu.mixins.json +++ b/src/main/resources/gtceu.mixins.json @@ -58,6 +58,7 @@ "ReloadableServerResourcesMixin", "RepairItemRecipeMixin", "ResourceKeyArgumentAccessor", + "ResourceLocationMixin", "ServerChunkProviderMixin", "ServerGamePacketListenerImplAccessor", "ShapedRecipeAccessor", From 8791be73c4d18a1b287ce770a4ab1072c8e53aa2 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:28:53 +0300 Subject: [PATCH 13/17] Readd `@HideFromJS` to `Material.Builder#buildAndRegister` --- .../gregtechceu/gtceu/api/data/chemical/material/Material.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java index 4590680796b..c045bfd7c7a 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java +++ b/src/main/java/com/gregtechceu/gtceu/api/data/chemical/material/Material.java @@ -36,6 +36,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import dev.latvian.mods.rhino.util.HideFromJS; import dev.latvian.mods.rhino.util.RemapPrefixForJS; import it.unimi.dsi.fastutil.ints.IntArrayList; import it.unimi.dsi.fastutil.ints.IntList; From d9bdd6d668fa8a9f1735b817d1271d3e3cfb9500 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:29:17 +0300 Subject: [PATCH 14/17] Fix multiline component/text module serializarion --- .../api/placeholder/GraphicsComponent.java | 24 +++---- .../api/placeholder/MultiLineComponent.java | 63 ++++++------------- .../behavior/modules/TextModuleBehaviour.java | 29 ++++----- .../item/datacomponents/FormatStringList.java | 3 +- 4 files changed, 41 insertions(+), 78 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/api/placeholder/GraphicsComponent.java b/src/main/java/com/gregtechceu/gtceu/api/placeholder/GraphicsComponent.java index ffcac24e9da..e3d8908c8a7 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/placeholder/GraphicsComponent.java +++ b/src/main/java/com/gregtechceu/gtceu/api/placeholder/GraphicsComponent.java @@ -6,8 +6,6 @@ import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.NbtOps; -import net.minecraft.nbt.Tag; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.serialization.Codec; @@ -18,18 +16,20 @@ public record GraphicsComponent(float x, float y, float x2, float y2, String rendererId, CompoundTag renderData) implements Supplier { - public GraphicsComponent(double x, double y, double x2, double y2, String rendererId, CompoundTag renderData) { - this((float) x, (float) y, (float) x2, (float) y2, rendererId, renderData); - } - + // spotless:off public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( Codec.FLOAT.fieldOf("x").forGetter(GraphicsComponent::x), Codec.FLOAT.fieldOf("y").forGetter(GraphicsComponent::y), Codec.FLOAT.fieldOf("x2").forGetter(GraphicsComponent::x2), Codec.FLOAT.fieldOf("y2").forGetter(GraphicsComponent::y2), Codec.STRING.fieldOf("rendererId").forGetter(GraphicsComponent::rendererId), - CompoundTag.CODEC.fieldOf("renderData").forGetter(GraphicsComponent::renderData)) - .apply(instance, GraphicsComponent::new)); + CompoundTag.CODEC.fieldOf("renderData").forGetter(GraphicsComponent::renderData) + ).apply(instance, GraphicsComponent::new)); + // spotless:on + + public GraphicsComponent(double x, double y, double x2, double y2, String rendererId, CompoundTag renderData) { + this((float) x, (float) y, (float) x2, (float) y2, rendererId, renderData); + } @Override public IMonitorRenderer get() { @@ -48,12 +48,4 @@ public void render(CentralMonitorMachine machine, MonitorGroup group, float part } }; } - - public Tag toTag() { - return CODEC.encodeStart(NbtOps.INSTANCE, this).getOrThrow(); - } - - public static GraphicsComponent fromTag(Tag tag) { - return CODEC.decode(NbtOps.INSTANCE, tag).getOrThrow().getFirst(); - } } diff --git a/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java b/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java index 04f1c159c6f..1af66a91277 100644 --- a/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java +++ b/src/main/java/com/gregtechceu/gtceu/api/placeholder/MultiLineComponent.java @@ -1,14 +1,10 @@ package com.gregtechceu.gtceu.api.placeholder; import net.minecraft.ChatFormatting; -import net.minecraft.core.HolderLookup; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; -import net.minecraft.nbt.StringTag; -import net.minecraft.nbt.Tag; import net.minecraft.network.chat.*; import com.mojang.serialization.Codec; +import com.mojang.serialization.codecs.RecordCodecBuilder; import lombok.Getter; import lombok.Setter; import lombok.experimental.Accessors; @@ -17,21 +13,16 @@ import org.jetbrains.annotations.UnmodifiableView; import java.util.*; -import java.util.function.Function; import java.util.stream.Collectors; @Accessors(chain = true) public class MultiLineComponent extends ArrayList { // spotless:off - private static final Codec> COMPONENT_LIST_CODEC = ComponentSerialization.CODEC.listOf() - .xmap(components -> new MultiLineComponent(components.stream().map(Component::copy).toList()), - MultiLineComponent::toImmutable); - public static final Codec CODEC = RecordCodecBuilder.create(instance -> instance.group( - COMPONENT_LIST_CODEC.fieldOf("text").forGetter(Function.identity()), + ComponentSerialization.CODEC.listOf().fieldOf("text").forGetter(MultiLineComponent::toImmutable), GraphicsComponent.CODEC.listOf().orElse(Collections.emptyList()).fieldOf("graphics").forGetter(MultiLineComponent::getGraphics) - ).apply(instance, MultiLineComponent::new)); + ).apply(instance, MultiLineComponent::of)); // spotless:on @Getter @@ -47,6 +38,14 @@ public MultiLineComponent(List components) { super(components); } + protected static MultiLineComponent of(List lines, List graphics) { + MultiLineComponent component = lines.stream() + .map(Component::copy) + .collect(Collectors.toCollection(MultiLineComponent::new)); + component.addGraphics(graphics); + return component; + } + public static MultiLineComponent of(List lines) { return lines.stream() .map(Component::copy) @@ -54,7 +53,13 @@ public static MultiLineComponent of(List lines) { } public static MultiLineComponent of(Component c) { - return new MultiLineComponent(List.of(c.copy())); + return MultiLineComponent.of(c.copy()); + } + + public static MultiLineComponent of(MutableComponent c) { + MultiLineComponent value = new MultiLineComponent(); + value.add(c); + return value; } public static MultiLineComponent literal(char c) { @@ -173,38 +178,6 @@ public MultiLineComponent withStyle(ChatFormatting... style) { return Collections.unmodifiableList(this); } - public Tag toTag(HolderLookup.Provider registries) { - CompoundTag compoundTag = new CompoundTag(); - ListTag tag = new ListTag(); - for (MutableComponent component : this) { - tag.add(StringTag.valueOf(Component.Serializer.toJson(component, registries))); - } - compoundTag.put("text", tag); - ListTag graphicsTag = new ListTag(); - for (GraphicsComponent component : this.getGraphics()) { - graphicsTag.add(component.toTag()); - } - compoundTag.put("graphics", graphicsTag); - return compoundTag; - } - - public static MultiLineComponent fromTag(@Nullable Tag tag, HolderLookup.Provider registries) { - MultiLineComponent out = MultiLineComponent.empty(); - out.clear(); - if (tag == null) return out; - if (tag instanceof ListTag listTag) { - for (Tag i : listTag) { - out.add(Component.Serializer.fromJson(i.getAsString(), registries)); - } - } else if (tag instanceof CompoundTag compoundTag) { - ListTag textTag = compoundTag.getList("text", Tag.TAG_STRING); - for (Tag i : textTag) out.add(Component.Serializer.fromJson(i.getAsString(), registries)); - ListTag graphicsTag = compoundTag.getList("graphics", Tag.TAG_COMPOUND); - for (Tag i : graphicsTag) out.addGraphics(GraphicsComponent.fromTag(i)); - } - return out; - } - public long toLong() { if (this.isEmpty()) return 0; if (this.size() > 1) throw new NumberFormatException(this.toString()); diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/behavior/modules/TextModuleBehaviour.java b/src/main/java/com/gregtechceu/gtceu/common/item/behavior/modules/TextModuleBehaviour.java index f8f9d50e8b5..b30d0954e39 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/behavior/modules/TextModuleBehaviour.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/behavior/modules/TextModuleBehaviour.java @@ -1,6 +1,7 @@ package com.gregtechceu.gtceu.common.item.behavior.modules; import com.gregtechceu.gtceu.api.gui.GuiTextures; +import com.gregtechceu.gtceu.api.gui.widget.FloatInputWidget; import com.gregtechceu.gtceu.api.item.component.IAddInformation; import com.gregtechceu.gtceu.api.item.component.IMonitorModuleItem; import com.gregtechceu.gtceu.api.placeholder.MultiLineComponent; @@ -9,11 +10,11 @@ import com.gregtechceu.gtceu.client.renderer.monitor.IMonitorRenderer; import com.gregtechceu.gtceu.client.renderer.monitor.MonitorTextRenderer; import com.gregtechceu.gtceu.common.data.item.GTDataComponents; +import com.gregtechceu.gtceu.common.item.datacomponents.FormatStringList; import com.gregtechceu.gtceu.common.item.datacomponents.TextLineList; import com.gregtechceu.gtceu.common.machine.multiblock.electric.CentralMonitorMachine; import com.gregtechceu.gtceu.common.machine.multiblock.electric.monitor.MonitorGroup; import com.gregtechceu.gtceu.common.network.packets.SCPacketMonitorGroupNBTChange; -import com.gregtechceu.gtceu.data.item.GTDataComponents; import com.lowdragmc.lowdraglib.gui.widget.ButtonWidget; import com.lowdragmc.lowdraglib.gui.widget.Widget; @@ -28,14 +29,12 @@ import net.minecraft.world.item.TooltipFlag; import net.neoforged.neoforge.network.PacketDistributor; -import org.jetbrains.annotations.Nullable; - import org.apache.commons.lang3.mutable.MutableFloat; +import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.List; import java.util.UUID; -import java.util.function.Supplier; -import java.util.stream.Collectors; public class TextModuleBehaviour implements IMonitorModuleItem, IAddInformation { @@ -62,9 +61,9 @@ public void tick(ItemStack stack, CentralMonitorMachine machine, MonitorGroup gr } @Override - public IMonitorRenderer getRenderer(ItemStack stack, CentralMonitorMachine machine, MonitorGroup group) { + public IMonitorRenderer getRenderer(ItemStack stack) { TextLineList lines = stack.getOrDefault(GTDataComponents.TEXT_LINE_LIST, TextLineList.EMPTY); - return new MonitorTextRenderer(lines.lines(), Math.max(lines.scale(), 0.0001f)); + return new MonitorTextRenderer(MultiLineComponent.of(lines.lines()), Math.max(lines.scale(), 0.0001f)); } @Override @@ -128,19 +127,17 @@ public void setScale(ItemStack stack, float scale) { } public void setPlaceholderText(ItemStack stack, String text) { - List lines = new ArrayList<>(); - for (String line : text.split("\n")) { - lines.add(Component.literal(line)); - } - stack.update(GTDataComponents.TEXT_LINE_LIST, TextLineList.EMPTY, - textLineList -> textLineList.withLines(lines)); + List lines = Arrays.asList(text.split("\n")); + + stack.update(GTDataComponents.FORMAT_STRING_LIST, FormatStringList.EMPTY, + formatStringList -> formatStringList.withLines(lines)); } public String getPlaceholderText(ItemStack stack) { StringBuilder formatStringLines = new StringBuilder(); - List lines = stack.getOrDefault(GTDataComponents.FORMAT_STRING_LIST, FormatStringList.EMPTY).lines(); - for (Component line : lines) { - formatStringLines.append(line.getString()).append('\n'); + List lines = stack.getOrDefault(GTDataComponents.FORMAT_STRING_LIST, FormatStringList.EMPTY).lines(); + for (String line : lines) { + formatStringLines.append(line).append('\n'); } return formatStringLines.toString(); } diff --git a/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/FormatStringList.java b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/FormatStringList.java index ab0eab43b09..29cf0a35ecc 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/FormatStringList.java +++ b/src/main/java/com/gregtechceu/gtceu/common/item/datacomponents/FormatStringList.java @@ -5,13 +5,14 @@ import com.mojang.serialization.Codec; import io.netty.buffer.ByteBuf; +import lombok.With; import java.util.AbstractList; import java.util.ArrayList; import java.util.Collections; import java.util.List; -public record FormatStringList(List lines) { +public record FormatStringList(@With List lines) { public static final Codec CODEC = Codec.STRING.listOf() .xmap(FormatStringList::new, FormatStringList::lines); From 6f702af1bceb8a6744c6347139b66f32cbeab98e Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:29:54 +0300 Subject: [PATCH 15/17] Rename Limonite _BACK_ to Limonite because for some reason THAT was reverted TOO??? It's `Limonite` on 1.20??? --- .../java/com/gregtechceu/gtceu/common/data/GTOreVeins.java | 4 ++-- .../gtceu/common/data/materials/MaterialFlagAddition.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/GTOreVeins.java b/src/main/java/com/gregtechceu/gtceu/common/data/GTOreVeins.java index 6ef734a47e9..03c762a44a2 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/GTOreVeins.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/GTOreVeins.java @@ -245,7 +245,7 @@ public static void bootstrap(BootstrapContext context) { .biomes(BiomeTags.IS_NETHER) .veinedVeinGenerator(generator -> generator .oreBlock(new VeinBlockDefinition(Goethite, 3)) - .oreBlock(new VeinBlockDefinition(YellowLimonite, 2)) + .oreBlock(new VeinBlockDefinition(Limonite, 2)) .oreBlock(new VeinBlockDefinition(Hematite, 2)) .rareBlock(new VeinBlockDefinition(Gold, 1)) .rareBlockChance(0.075f) @@ -527,7 +527,7 @@ public static void bootstrap(BootstrapContext context) { .biomes(BiomeTags.IS_OVERWORLD) .veinedVeinGenerator(generator -> generator .oreBlock(new VeinBlockDefinition(Goethite, 5)) - .oreBlock(new VeinBlockDefinition(YellowLimonite, 2)) + .oreBlock(new VeinBlockDefinition(Limonite, 2)) .oreBlock(new VeinBlockDefinition(Hematite, 2)) .oreBlock(new VeinBlockDefinition(Malachite, 1)) .veininessThreshold(0.01f) diff --git a/src/main/java/com/gregtechceu/gtceu/common/data/materials/MaterialFlagAddition.java b/src/main/java/com/gregtechceu/gtceu/common/data/materials/MaterialFlagAddition.java index 9af9bdcaf91..52334c037c7 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/data/materials/MaterialFlagAddition.java +++ b/src/main/java/com/gregtechceu/gtceu/common/data/materials/MaterialFlagAddition.java @@ -103,7 +103,7 @@ public static void register() { oreProp.setOreByProducts(Topaz); oreProp = Goethite.getProperty(PropertyKey.ORE); - oreProp.setOreByProducts(Malachite, YellowLimonite); + oreProp.setOreByProducts(Malachite, Limonite); oreProp.setSeparatedInto(Iron); oreProp.setDirectSmeltResult(Iron); @@ -256,7 +256,7 @@ public static void register() { oreProp = Uraninite.getProperty(PropertyKey.ORE); oreProp.setOreByProducts(Uraninite, Thorium, Silver); - oreProp = YellowLimonite.getProperty(PropertyKey.ORE); + oreProp = Limonite.getProperty(PropertyKey.ORE); oreProp.setOreByProducts(Nickel, Goethite, CobaltOxide); oreProp.setSeparatedInto(Iron); oreProp.setWashedIn(SodiumPersulfate); From f33bb110b6bd3513f7d103234d188aac48d04c95 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 20:30:34 +0300 Subject: [PATCH 16/17] Clean up WA blacklist to not be so 1.12-like It actually uses block entity types now --- .../renderer/BlockHighlightRenderer.java | 4 +- .../electric/WorldAcceleratorMachine.java | 101 ++++++++---------- 2 files changed, 46 insertions(+), 59 deletions(-) diff --git a/src/main/java/com/gregtechceu/gtceu/client/renderer/BlockHighlightRenderer.java b/src/main/java/com/gregtechceu/gtceu/client/renderer/BlockHighlightRenderer.java index b460980c85a..72e3089331a 100644 --- a/src/main/java/com/gregtechceu/gtceu/client/renderer/BlockHighlightRenderer.java +++ b/src/main/java/com/gregtechceu/gtceu/client/renderer/BlockHighlightRenderer.java @@ -276,10 +276,10 @@ private static void drawLine(PoseStack.Pose pose, VertexConsumer buffer, Vector3 buffer.addVertex(pose.pose(), from.x(), from.y(), from.z()) .setColor(rColour, gColour, bColour, 1f) - .setNormal(pose.normal(), normal.x(), normal.y(), normal.z()); + .setNormal(pose, normal.x(), normal.y(), normal.z()); buffer.addVertex(pose.pose(), to.x(), to.y(), to.z()) .setColor(rColour, gColour, bColour, 1f) - .setNormal(pose.normal(), normal.x(), normal.y(), normal.z()); + .setNormal(pose, normal.x(), normal.y(), normal.z()); } private static void drawResourceTexture(PoseStack poseStack, MultiBufferSource bufferSource, diff --git a/src/main/java/com/gregtechceu/gtceu/common/machine/electric/WorldAcceleratorMachine.java b/src/main/java/com/gregtechceu/gtceu/common/machine/electric/WorldAcceleratorMachine.java index c06921a20e4..6154a965f47 100644 --- a/src/main/java/com/gregtechceu/gtceu/common/machine/electric/WorldAcceleratorMachine.java +++ b/src/main/java/com/gregtechceu/gtceu/common/machine/electric/WorldAcceleratorMachine.java @@ -25,40 +25,37 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; import net.minecraft.world.ItemInteractionResult; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.BooleanProperty; import net.minecraft.world.phys.BlockHitResult; -import it.unimi.dsi.fastutil.objects.Object2BooleanFunction; -import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import lombok.Getter; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.Set; public class WorldAcceleratorMachine extends TieredEnergyMachine implements IControllable { - private static final Map> blacklistedClasses = new Object2ObjectOpenHashMap<>(); - private static final Object2BooleanFunction> blacklistCache = new Object2BooleanOpenHashMap<>(); + private static final Set> blacklistedTypes = new ObjectOpenHashSet<>(); private static boolean gatheredClasses = false; - // Hard-coded blacklist for blockentities - private static final List blockEntityClassNamesBlackList = new ArrayList<>(); - - public static final BooleanProperty RANDOM_TICK_PROPERTY = GTMachineModelProperties.IS_RANDOM_TICK_MODE; + // Hardcoded blacklist for block entity types + private static final List blockEntityTypeBlackList = new ArrayList<>(); protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder( WorldAcceleratorMachine.class, TieredEnergyMachine.MANAGED_FIELD_HOLDER); @@ -84,7 +81,7 @@ public class WorldAcceleratorMachine extends TieredEnergyMachine implements ICon @DescSynced @RequireRerender private boolean active = false; - private TickableSubscription tickSubs; + private @Nullable TickableSubscription tickSubs; public WorldAcceleratorMachine(IMachineBlockEntity holder, int tier, Object... args) { super(holder, tier, GTMachineUtils.defaultTankSizeFunction, args); @@ -94,13 +91,13 @@ public WorldAcceleratorMachine(IMachineBlockEntity holder, int tier, Object... a } @Override - protected @NotNull NotifiableEnergyContainer createEnergyContainer(Object @NotNull... args) { + protected NotifiableEnergyContainer createEnergyContainer(Object @NotNull... args) { long tierVoltage = GTValues.V[getTier()]; return new NotifiableEnergyContainer(this, tierVoltage * 256L, tierVoltage, 8, 0L, 0L); } @Override - public @NotNull ManagedFieldHolder getFieldHolder() { + public ManagedFieldHolder getFieldHolder() { return MANAGED_FIELD_HOLDER; } @@ -166,15 +163,18 @@ public boolean drainEnergy(boolean simulate) { return false; } - private void tickBlockEntity(@NotNull T blockEntity) { + private void tickBlockEntity(T blockEntity) { BlockPos pos = blockEntity.getBlockPos(); - // noinspection unchecked - BlockEntityTicker blockEntityTicker = this.getLevel().getBlockState(pos).getTicker(this.getLevel(), - (BlockEntityType) blockEntity.getType()); - if (blockEntityTicker == null) return; + Level level = blockEntity.getLevel(); + if (level == null) return; + + @SuppressWarnings("unchecked") + BlockEntityTicker ticker = level.getBlockState(pos) + .getTicker(level, (BlockEntityType) blockEntity.getType()); + if (ticker == null) return; + for (int i = 0; i < speed - 1; i++) { - blockEntityTicker.tick(blockEntity.getLevel(), blockEntity.getBlockPos(), blockEntity.getBlockState(), - blockEntity); + ticker.tick(level, blockEntity.getBlockPos(), blockEntity.getBlockState(), blockEntity); } } @@ -182,21 +182,7 @@ private boolean canAccelerate(BlockEntity blockEntity) { if (blockEntity instanceof PipeBlockEntity || blockEntity instanceof IMachineBlockEntity) return false; generateWorldAcceleratorBlacklist(); - final Class blockEntityClass = blockEntity.getClass(); - if (blacklistCache.containsKey(blockEntityClass)) { - return blacklistCache.getBoolean(blockEntityClass); - } - - for (Class clazz : blacklistedClasses.values()) { - if (clazz.isAssignableFrom(blockEntityClass)) { - // Is a subclass, so it cannot be accelerated - blacklistCache.put(blockEntityClass, false); - return false; - } - } - - blacklistCache.put(blockEntityClass, true); - return true; + return blacklistedTypes.contains(blockEntity.getType()); } @Override @@ -223,8 +209,8 @@ public void setWorkingEnabled(boolean workingEnabled) { } @Override - public ResourceTexture sideTips(Player player, BlockPos pos, BlockState state, Set toolTypes, - ItemStack held, Direction side) { + public @Nullable ResourceTexture sideTips(Player player, BlockPos pos, BlockState state, Set toolTypes, + ItemStack held, Direction side) { if (toolTypes.contains(GTToolType.SOFT_MALLET)) { return isWorkingEnabled ? GuiTextures.TOOL_PAUSE : GuiTextures.TOOL_START; } @@ -250,9 +236,9 @@ protected ItemInteractionResult onSoftMalletClick(Player playerIn, InteractionHa } @Override - protected @NotNull ItemInteractionResult onScrewdriverClick(Player playerIn, InteractionHand hand, - ItemStack held, Direction gridSide, - BlockHitResult hitResult) { + protected ItemInteractionResult onScrewdriverClick(Player playerIn, InteractionHand hand, + ItemStack held, Direction gridSide, + BlockHitResult hitResult) { if (!isRemote()) { isRandomTickMode = !isRandomTickMode; setRenderState(getRenderState().setValue(GTMachineModelProperties.IS_RANDOM_TICK_MODE, isRandomTickMode)); @@ -264,24 +250,25 @@ protected ItemInteractionResult onSoftMalletClick(Player playerIn, InteractionHa } private static void generateWorldAcceleratorBlacklist() { - if (!gatheredClasses) { - for (String name : ConfigHolder.INSTANCE.machines.worldAcceleratorBlacklist) { - if (!blacklistedClasses.containsKey(name)) { - try { - blacklistedClasses.put(name, Class.forName(name)); - } catch (ClassNotFoundException ignored) { - GTCEu.LOGGER.warn("Could not find class {} for World Accelerator Blacklist!", name); - } - } - } + if (gatheredClasses) { + return; + } + for (ResourceLocation id : blockEntityTypeBlackList) { + BlockEntityType type = BuiltInRegistries.BLOCK_ENTITY_TYPE.get(id); + if (type == null) continue; + blacklistedTypes.add(type); + } - for (String className : blockEntityClassNamesBlackList) { - try { - blacklistedClasses.put(className, Class.forName(className)); - } catch (ClassNotFoundException ignored) {} + for (ResourceLocation id : ConfigHolder.INSTANCE.machines.worldAcceleratorBlacklist) { + BlockEntityType type = BuiltInRegistries.BLOCK_ENTITY_TYPE.get(id); + if (blacklistedTypes.contains(type)) continue; + if (type == null) { + GTCEu.LOGGER.warn("Could not find block entity type {} for World Accelerator Blacklist!", id); + continue; } - - gatheredClasses = true; + blacklistedTypes.add(type); } + + gatheredClasses = true; } } From e6876a67bc15b1cbcc9862fef9bc84dfdfa47f39 Mon Sep 17 00:00:00 2001 From: screret <68943070+screret@users.noreply.github.com> Date: Mon, 6 Apr 2026 22:05:24 +0300 Subject: [PATCH 17/17] Add back the datafix hook mixins --- .../mixins/ChunkSerializerDataFixMixin.java | 23 +++++++++++ .../core/mixins/DataFixTypesDataFixMixin.java | 28 +++++++++++++ .../core/mixins/IOWorkerDataFixMixin.java | 26 ++++++++++++ .../mixins/StructureTemplateDataFixMixin.java | 22 ++++++++++ .../client/HotbarManagerDataFixMixin.java | 40 +++++++++++++++++++ src/main/resources/gtceu.mixins.json | 5 +++ 6 files changed, 144 insertions(+) create mode 100644 src/main/java/com/gregtechceu/gtceu/core/mixins/ChunkSerializerDataFixMixin.java create mode 100644 src/main/java/com/gregtechceu/gtceu/core/mixins/DataFixTypesDataFixMixin.java create mode 100644 src/main/java/com/gregtechceu/gtceu/core/mixins/IOWorkerDataFixMixin.java create mode 100644 src/main/java/com/gregtechceu/gtceu/core/mixins/StructureTemplateDataFixMixin.java create mode 100644 src/main/java/com/gregtechceu/gtceu/core/mixins/client/HotbarManagerDataFixMixin.java diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/ChunkSerializerDataFixMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/ChunkSerializerDataFixMixin.java new file mode 100644 index 00000000000..0b703c913a7 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/ChunkSerializerDataFixMixin.java @@ -0,0 +1,23 @@ +package com.gregtechceu.gtceu.core.mixins; + +import com.gregtechceu.gtceu.api.datafixer.DataFixesInternals; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.chunk.storage.ChunkSerializer; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(ChunkSerializer.class) +public abstract class ChunkSerializerDataFixMixin { + + @ModifyVariable( + method = "write", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/nbt/CompoundTag;putInt(Ljava/lang/String;I)V", + ordinal = 0)) + private static CompoundTag gtceu$addModDataVersions(CompoundTag compound) { + return DataFixesInternals.get().addModDataVersions(compound); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/DataFixTypesDataFixMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/DataFixTypesDataFixMixin.java new file mode 100644 index 00000000000..4cb6e73d62e --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/DataFixTypesDataFixMixin.java @@ -0,0 +1,28 @@ +package com.gregtechceu.gtceu.core.mixins; + +import com.gregtechceu.gtceu.api.datafixer.DataFixesInternals; + +import net.minecraft.util.datafix.DataFixTypes; + +import com.llamalad7.mixinextras.injector.ModifyReturnValue; +import com.mojang.datafixers.DSL; +import com.mojang.serialization.Dynamic; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(DataFixTypes.class) +public class DataFixTypesDataFixMixin { + + @Shadow + @Final + private DSL.TypeReference type; + + // ModifyReturnValue to inject our fixes *after* vanilla ones + @ModifyReturnValue(method = "update(Lcom/mojang/datafixers/DataFixer;Lcom/mojang/serialization/Dynamic;II)Lcom/mojang/serialization/Dynamic;", + at = @At(value = "RETURN")) + private Dynamic gtceu$injectDataFixers(Dynamic value) { + return DataFixesInternals.get().updateWithAllFixers(this.type, value); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/IOWorkerDataFixMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/IOWorkerDataFixMixin.java new file mode 100644 index 00000000000..6a1b11235d5 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/IOWorkerDataFixMixin.java @@ -0,0 +1,26 @@ +package com.gregtechceu.gtceu.core.mixins; + +import com.gregtechceu.gtceu.api.datafixer.DataFixesInternals; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.ChunkPos; +import net.minecraft.world.level.chunk.storage.IOWorker; + +import org.jetbrains.annotations.Nullable; +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 java.util.concurrent.CompletableFuture; + +@Mixin(IOWorker.class) +public class IOWorkerDataFixMixin { + + @Inject(method = "store", at = @At("HEAD")) + private void gtceu$addModDataVersions(ChunkPos chunkPos, @Nullable CompoundTag chunkData, + CallbackInfoReturnable> cir) { + if (chunkData != null) + DataFixesInternals.get().addModDataVersions(chunkData); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/StructureTemplateDataFixMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/StructureTemplateDataFixMixin.java new file mode 100644 index 00000000000..0ac242eae85 --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/StructureTemplateDataFixMixin.java @@ -0,0 +1,22 @@ +package com.gregtechceu.gtceu.core.mixins; + +import com.gregtechceu.gtceu.api.datafixer.DataFixesInternals; + +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate; + +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; + +@Mixin(StructureTemplate.class) +public abstract class StructureTemplateDataFixMixin { + + @Inject(method = "save", at = @At("TAIL"), cancellable = true) + private void addModDataVersions(CompoundTag compound, CallbackInfoReturnable cir) { + CompoundTag out = cir.getReturnValue(); + DataFixesInternals.get().addModDataVersions(out); + cir.setReturnValue(out); + } +} diff --git a/src/main/java/com/gregtechceu/gtceu/core/mixins/client/HotbarManagerDataFixMixin.java b/src/main/java/com/gregtechceu/gtceu/core/mixins/client/HotbarManagerDataFixMixin.java new file mode 100644 index 00000000000..86c0170a07a --- /dev/null +++ b/src/main/java/com/gregtechceu/gtceu/core/mixins/client/HotbarManagerDataFixMixin.java @@ -0,0 +1,40 @@ +/* + * Copyright 2022 QuiltMC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gregtechceu.gtceu.core.mixins.client; + +import com.gregtechceu.gtceu.api.datafixer.DataFixesInternals; + +import net.minecraft.client.HotbarManager; +import net.minecraft.nbt.CompoundTag; + +import com.llamalad7.mixinextras.sugar.Local; +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.CallbackInfo; + +@Mixin(HotbarManager.class) +public abstract class HotbarManagerDataFixMixin { + + @Inject( + method = "save", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/nbt/NbtIo;write(Lnet/minecraft/nbt/CompoundTag;Ljava/nio/file/Path;)V", + shift = At.Shift.AFTER)) + private void gtceu$addModDataVersions(CallbackInfo ci, @Local CompoundTag tag) { + DataFixesInternals.get().addModDataVersions(tag); + } +} diff --git a/src/main/resources/gtceu.mixins.json b/src/main/resources/gtceu.mixins.json index 9b955e2b2f5..de34bff6332 100644 --- a/src/main/resources/gtceu.mixins.json +++ b/src/main/resources/gtceu.mixins.json @@ -13,6 +13,7 @@ "client.FaceBakeryMixin", "client.GuiGraphicsAccessor", "client.GuiGraphicsMixin", + "client.HotbarManagerDataFixMixin", "client.ItemEntityMixin", "client.LevelRendererMixin", "client.ModelManagerMixin", @@ -38,12 +39,15 @@ "BlockMixin", "BlockPropertiesAccessor", "ChunkGeneratorMixin", + "ChunkSerializerDataFixMixin", + "DataFixTypesDataFixMixin", "EntityAccessor", "EntityMixin", "FluidStackAccessor", "GrowingPlantBlockAccessor", "IntegerPropertyAccessor", "InventoryMixin", + "IOWorkerDataFixMixin", "LevelAccessor", "LevelMixin", "LootPoolAccessor", @@ -63,6 +67,7 @@ "ServerGamePacketListenerImplAccessor", "ShapedRecipeAccessor", "SidedRedstoneConnectivityMixin", + "StructureTemplateDataFixMixin", "TagLoaderMixin", "TagManagerMixin", "WorldLoaderMixin",