Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 43 additions & 16 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ neoForge {
layout.buildDirectory.file("generated/access-transformer/accesstransformer.cfg")
)

parchment {
minecraftVersion = commonMod.prop("parchment_minecraft")
mappingsVersion = commonMod.prop("parchment_version")
val parchment_minecraft = commonMod.prop("parchment_minecraft")
val parchment_version = commonMod.prop("parchment_version")
// Parchment does not yet ship mappings for 26.1.x; skip the layer when
// either property is blank. TODO(26.1): re-enable once parchment publishes.
if (parchment_minecraft.isNotBlank() && parchment_version.isNotBlank()) {
parchment {
minecraftVersion = parchment_minecraft
mappingsVersion = parchment_version
}
}
}

Expand Down Expand Up @@ -73,19 +79,40 @@ val accessTransformerFile = layout.buildDirectory.file("generated/access-transfo
val accessWidenerFile = rootProject.file(
"common/src/main/resources/accesswideners/$minecraft_version-$mod_id.accesswidener"
)
val generateAccessTransformer by tasks.registering(Copy::class) {
from(accessWidenerFile)
into(accessTransformerFile.map { it.asFile.parentFile })
rename { "accesstransformer.cfg" }
val transformerClass = Class.forName(
"dev.kikugie.fletching_table.transformer.Aw2AtFileTransformer"
) as Class<out FilterReader>
val argsClass = Class.forName(
"dev.kikugie.fletching_table.transformer.Aw2AtFileTransformer\$TransformArgs"
)
val args = argsClass.getDeclaredConstructor(Path::class.java)
.newInstance(accessWidenerFile.toPath())
filter(mapOf("args" to args), transformerClass)

// MC 26.1+ ships deobfuscated, so the access widener uses the `official`
// namespace. Aw2AtFileTransformer only accepts `named`, and 26.1 does not
// build NeoForge (which is the only consumer of the generated AT file).
// On 26.1 we still emit an empty AT stub at the canonical path because
// neoform's createMinecraftArtifacts hashes the file as part of its cache
// key, and a missing path crashes the task.
val isDeobfuscatedMc = minecraft_version.startsWith("26.")

val generateAccessTransformer = if (isDeobfuscatedMc) {
tasks.register("generateAccessTransformer") {
val outFile = accessTransformerFile
outputs.file(outFile)
doLast {
val target = outFile.get().asFile
target.parentFile.mkdirs()
target.writeText("# Empty AT stub for 26.1 (deobfuscated, NeoForge unsupported).\n")
}
}
} else {
tasks.register("generateAccessTransformer", Copy::class.java) {
from(accessWidenerFile)
into(accessTransformerFile.map { it.asFile.parentFile })
rename { "accesstransformer.cfg" }
val transformerClass = Class.forName(
"dev.kikugie.fletching_table.transformer.Aw2AtFileTransformer"
) as Class<out FilterReader>
val argsClass = Class.forName(
"dev.kikugie.fletching_table.transformer.Aw2AtFileTransformer\$TransformArgs"
)
val args = argsClass.getDeclaredConstructor(Path::class.java)
.newInstance(accessWidenerFile.toPath())
filter(mapOf("args" to args), transformerClass)
}
}

tasks.named("createMinecraftArtifacts") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.jsmacrosce.jsmacros.client.access;

//? if >=26.1 {
/*import net.minecraft.client.gui.GuiGraphicsExtractor;
*///?} else {
import net.minecraft.client.gui.GuiGraphics;
//?}
import com.jsmacrosce.doclet.DocletIgnore;

@DocletIgnore
public interface IScreenInternal {
//? if >=26.1 {
/*void jsmacros_render(GuiGraphicsExtractor drawContext, int mouseX, int mouseY, float delta);
*///?} else {
void jsmacros_render(GuiGraphics drawContext, int mouseX, int mouseY, float delta);
//?}

void jsmacros_mouseClicked(double mouseX, double mouseY, int button);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ public Collection<String> getSelectedEntities() {
}

@Override
//? if >=26.1 {
/*public Collection<String> getCustomTabSuggestions() {
return source.getCustomTabSuggestions();
}
*///?} else {
public Collection<String> getCustomTabSugggestions() {
return source.getCustomTabSugggestions();
}
//?}

@Override
public Collection<String> getOnlinePlayerNames() {
Expand Down Expand Up @@ -92,7 +98,11 @@ public RegistryAccess registryAccess() {

@Override
public void sendSuccess(Supplier<Component> feedbackSupplier, boolean broadcastToOps) {
//? if >=26.1 {
/*Minecraft.getInstance().player.sendSystemMessage(feedbackSupplier.get());
*///?} else {
Minecraft.getInstance().player.displayClientMessage(feedbackSupplier.get(), false);
//?}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.commands.arguments.blocks.BlockStateParser;
import net.minecraft.commands.arguments.item.ItemParser;
//? if >=26.1 {
/*import net.minecraft.commands.arguments.item.ItemInput;
*///?}
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -100,7 +103,11 @@ public ItemStackHelper getItemStack(String id) {
@DocletReplaceParams("id: CanOmitNamespace<ItemId>, nbt: string")
public ItemStackHelper getItemStack(String id, String nbt) throws CommandSyntaxException {
ItemParser reader = new ItemParser(Objects.requireNonNull(mc.getConnection()).registryAccess());
//? if >=26.1 {
/*ItemInput itemResult = reader.parse(new StringReader(parseNameSpace(id) + nbt));
*///?} else {
ItemParser.ItemResult itemResult = reader.parse(new StringReader(parseNameSpace(id) + nbt));
//?}
ItemStack stack = new ItemStack(itemResult.item());
stack.applyComponents(itemResult.components());
return new CreativeItemStackHelper(stack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;
//? if >=26.1 {
/*import net.minecraft.world.item.ItemStackTemplate;
*///?}
import com.jsmacrosce.doclet.DocletReplaceParams;
import com.jsmacrosce.jsmacros.access.CustomClickEvent;
import com.jsmacrosce.jsmacros.client.JsMacrosClient;
Expand Down Expand Up @@ -152,7 +155,13 @@ public TextBuilder withShowTextHover(TextHelper text) {
* @since 1.3.0
*/
public TextBuilder withShowItemHover(ItemStackHelper item) {
//? if >=26.1 {
/*if (!item.getRaw().isEmpty()) {
self.withStyle(style -> style.withHoverEvent(new HoverEvent.ShowItem(ItemStackTemplate.fromNonEmptyStack(item.getRaw()))));
}
*///?} else {
self.withStyle(style -> style.withHoverEvent(new HoverEvent.ShowItem(item.getRaw())));
//?}
return this;
}
Comment on lines 157 to 166
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Cross-version behavior divergence for empty stacks.

On 26.1, an empty stack silently leaves the style without a hover event; on older versions, a ShowItem hover is still attached for AIR/empty stacks. Callers chaining .withShowItemHover(empty) will see different runtime behavior depending on the target version. Consider guarding both branches identically (or documenting the no-op) so the API contract stays stable.

🔧 Proposed alignment
     public TextBuilder withShowItemHover(ItemStackHelper item) {
+        if (item.getRaw().isEmpty()) return this;
         //? if >=26.1 {
-        /*if (!item.getRaw().isEmpty()) {
-            self.withStyle(style -> style.withHoverEvent(new HoverEvent.ShowItem(ItemStackTemplate.fromNonEmptyStack(item.getRaw()))));
-        }
+        /*self.withStyle(style -> style.withHoverEvent(new HoverEvent.ShowItem(ItemStackTemplate.fromNonEmptyStack(item.getRaw()))));
         *///?} else {
         self.withStyle(style -> style.withHoverEvent(new HoverEvent.ShowItem(item.getRaw())));
         //?}
         return this;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public TextBuilder withShowItemHover(ItemStackHelper item) {
//? if >=26.1 {
/*if (!item.getRaw().isEmpty()) {
self.withStyle(style -> style.withHoverEvent(new HoverEvent.ShowItem(ItemStackTemplate.fromNonEmptyStack(item.getRaw()))));
}
*///?} else {
self.withStyle(style -> style.withHoverEvent(new HoverEvent.ShowItem(item.getRaw())));
//?}
return this;
}
public TextBuilder withShowItemHover(ItemStackHelper item) {
if (item.getRaw().isEmpty()) return this;
//? if >=26.1 {
/*self.withStyle(style -> style.withHoverEvent(new HoverEvent.ShowItem(ItemStackTemplate.fromNonEmptyStack(item.getRaw()))));
*///?} else {
self.withStyle(style -> style.withHoverEvent(new HoverEvent.ShowItem(item.getRaw())));
//?}
return this;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@common/src/main/java/com/jsmacrosce/jsmacros/client/api/classes/TextBuilder.java`
around lines 157 - 166, The withShowItemHover method in TextBuilder currently
differs by Minecraft version: newer branch skips attaching a hover for empty
stacks but the older branch always attaches a ShowItem (including AIR), causing
inconsistent API behavior; update the method (TextBuilder.withShowItemHover) to
perform the same emptiness guard in both branches by checking
item.getRaw().isEmpty() (or ItemStackHelper.isEmpty) before calling
self.withStyle(...) and only attach HoverEvent.ShowItem (using
HoverEvent.ShowItem and ItemStackTemplate.fromNonEmptyStack where applicable)
when the stack is non-empty so both code paths are identical no-ops for empty
stacks.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import net.minecraft.world.entity.animal.horse.AbstractHorse;
//? }
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ClickType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.Nullable;
Expand All @@ -32,6 +31,7 @@
import com.jsmacrosce.jsmacros.client.access.IInventory;
import com.jsmacrosce.jsmacros.client.api.helper.inventory.ItemStackHelper;
import com.jsmacrosce.jsmacros.client.api.library.impl.FClient;
import com.jsmacrosce.jsmacros.util.ContainerInputCompat;

import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -137,8 +137,8 @@ public Inventory<T> click(int slot) {
*/
@DocletReplaceParams("slot: int, mousebutton: Trit")
public Inventory<T> click(int slot, int mousebutton) {
ClickType act = mousebutton == 2 ? ClickType.CLONE : ClickType.PICKUP;
man.handleInventoryMouseClick(syncId, slot, mousebutton, act, player);
int action = mousebutton == 2 ? ContainerInputCompat.CLONE : ContainerInputCompat.PICKUP;
ContainerInputCompat.dispatch(man, syncId, slot, mousebutton, action, player);
return this;
}

Expand All @@ -152,11 +152,11 @@ public Inventory<T> click(int slot, int mousebutton) {
@DocletReplaceParams("slots: int[], mousebutton: Bit")
public Inventory<T> dragClick(int[] slots, int mousebutton) {
mousebutton = mousebutton == 0 ? 1 : 5;
man.handleInventoryMouseClick(syncId, -999, mousebutton - 1, ClickType.QUICK_CRAFT, player); // start drag click
ContainerInputCompat.dispatch(man, syncId, -999, mousebutton - 1, ContainerInputCompat.QUICK_CRAFT, player); // start drag click
for (int i : slots) {
man.handleInventoryMouseClick(syncId, i, mousebutton, ClickType.QUICK_CRAFT, player);
ContainerInputCompat.dispatch(man, syncId, i, mousebutton, ContainerInputCompat.QUICK_CRAFT, player);
}
man.handleInventoryMouseClick(syncId, -999, mousebutton + 1, ClickType.QUICK_CRAFT, player);
ContainerInputCompat.dispatch(man, syncId, -999, mousebutton + 1, ContainerInputCompat.QUICK_CRAFT, player);
return this;
}

Expand All @@ -165,7 +165,7 @@ public Inventory<T> dragClick(int[] slots, int mousebutton) {
* @since 1.5.0
*/
public Inventory<T> dropSlot(int slot) {
man.handleInventoryMouseClick(syncId, slot, 0, ClickType.THROW, player);
ContainerInputCompat.dispatch(man, syncId, slot, 0, ContainerInputCompat.THROW, player);
return this;
}

Expand All @@ -176,7 +176,7 @@ public Inventory<T> dropSlot(int slot) {
* @since 1.8.4
*/
public Inventory<T> dropSlot(int slot, boolean stack) {
man.handleInventoryMouseClick(syncId, slot, stack ? 1 : 0, ClickType.THROW, player);
ContainerInputCompat.dispatch(man, syncId, slot, stack ? 1 : 0, ContainerInputCompat.THROW, player);
return this;
}

Expand Down Expand Up @@ -337,7 +337,7 @@ public void setSelectedHotbarSlotIndex(int index) {
public Inventory<T> closeAndDrop() {
ItemStack held = handler.getCarried();
if (!held.isEmpty()) {
man.handleInventoryMouseClick(syncId, -999, 0, ClickType.PICKUP, player);
ContainerInputCompat.dispatch(man, syncId, -999, 0, ContainerInputCompat.PICKUP, player);
}
close();
return this;
Expand All @@ -360,7 +360,7 @@ public void close() {
* @return
*/
public Inventory<T> quick(int slot) {
man.handleInventoryMouseClick(syncId, slot, 0, ClickType.QUICK_MOVE, player);
ContainerInputCompat.dispatch(man, syncId, slot, 0, ContainerInputCompat.QUICK_MOVE, player);
return this;
}

Expand Down Expand Up @@ -393,7 +393,7 @@ public int quickAll(int slot, int button) {
&& slot2.container == hoverSlotInv
&& AbstractContainerMenu.canItemQuickReplace(slot2, cursorStack, true)) {
count += slot2.getItem().getCount();
man.handleInventoryMouseClick(syncId, slot2.index, button, ClickType.QUICK_MOVE, player);
ContainerInputCompat.dispatch(man, syncId, slot2.index, button, ContainerInputCompat.QUICK_MOVE, player);
}
}
return count;
Expand Down Expand Up @@ -436,8 +436,8 @@ public Inventory<T> split(int slot1, int slot2) throws Exception {
if (!getSlot(slot1).isEmpty() || !getSlot(slot2).isEmpty()) {
throw new Exception("slots must be empty.");
}
man.handleInventoryMouseClick(syncId, slot1, 1, ClickType.PICKUP, player);
man.handleInventoryMouseClick(syncId, slot2, 0, ClickType.PICKUP, player);
ContainerInputCompat.dispatch(man, syncId, slot1, 1, ContainerInputCompat.PICKUP, player);
ContainerInputCompat.dispatch(man, syncId, slot2, 0, ContainerInputCompat.PICKUP, player);
return this;
}

Expand All @@ -448,8 +448,8 @@ public Inventory<T> split(int slot1, int slot2) throws Exception {
* @return
*/
public Inventory<T> grabAll(int slot) {
man.handleInventoryMouseClick(syncId, slot, 0, ClickType.PICKUP, player);
man.handleInventoryMouseClick(syncId, slot, 0, ClickType.PICKUP_ALL, player);
ContainerInputCompat.dispatch(man, syncId, slot, 0, ContainerInputCompat.PICKUP, player);
ContainerInputCompat.dispatch(man, syncId, slot, 0, ContainerInputCompat.PICKUP_ALL, player);
return this;
}

Expand All @@ -469,11 +469,11 @@ public Inventory<T> swap(int slot1, int slot2) {
return this;
}
if (!is1) {
man.handleInventoryMouseClick(syncId, slot1, 0, ClickType.PICKUP, player);
ContainerInputCompat.dispatch(man, syncId, slot1, 0, ContainerInputCompat.PICKUP, player);
}
man.handleInventoryMouseClick(syncId, slot2, 0, ClickType.PICKUP, player);
ContainerInputCompat.dispatch(man, syncId, slot2, 0, ContainerInputCompat.PICKUP, player);
if (!is2) {
man.handleInventoryMouseClick(syncId, slot1, 0, ClickType.PICKUP, player);
ContainerInputCompat.dispatch(man, syncId, slot1, 0, ContainerInputCompat.PICKUP, player);
}
return this;
}
Expand All @@ -494,7 +494,7 @@ public Inventory<T> swapHotbar(int slot, int hotbarSlot) {
throw new IllegalArgumentException("hotbarSlot must be between 0 and 8 or 40 for offhand.");
}
}
man.handleInventoryMouseClick(syncId, slot, hotbarSlot, ClickType.SWAP, player);
ContainerInputCompat.dispatch(man, syncId, slot, hotbarSlot, ContainerInputCompat.SWAP, player);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import com.google.common.collect.ImmutableList;
import net.minecraft.client.gui.screens.inventory.LoomScreen;
import net.minecraft.core.Holder;
//? if >=26.1 {
/*import net.minecraft.core.HolderSet;
*///?}
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.Registries;
import net.minecraft.tags.BannerPatternTags;
Expand Down Expand Up @@ -32,8 +35,13 @@ private List<Holder<BannerPattern>> getPatternsFor(ItemStack stack) {
if (stack.isEmpty()) {
return bannerPatternLookup.get(BannerPatternTags.NO_ITEM_REQUIRED).map(ImmutableList::copyOf).orElse(ImmutableList.of());
} else {
//? if >=26.1 {
/*HolderSet<BannerPattern> holders = stack.get(DataComponents.PROVIDES_BANNER_PATTERNS);
return holders != null ? ImmutableList.copyOf(holders) : List.of();
*///?} else {
TagKey<BannerPattern> tagKey = stack.get(DataComponents.PROVIDES_BANNER_PATTERNS);
return tagKey != null ? bannerPatternLookup.get(tagKey).map(ImmutableList::copyOf).orElse(ImmutableList.of()) : List.of();
//?}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import com.google.common.collect.ImmutableList;
import net.minecraft.client.Minecraft;
//? if >=26.1 {
/*import net.minecraft.client.gui.GuiGraphicsExtractor;
*///?} else {
import net.minecraft.client.gui.GuiGraphics;
//?}
import net.minecraft.client.gui.components.Renderable;
import org.jetbrains.annotations.Nullable;
import com.jsmacrosce.doclet.DocletIgnore;
Expand Down Expand Up @@ -591,15 +595,23 @@ public void init() {

@Override
@DocletIgnore
//? if >=26.1 {
/*public void render(GuiGraphicsExtractor drawContext) {
*///?} else {
public void render(GuiGraphics drawContext) {
//?}
if (drawContext == null || !visible) {
return;
}

synchronized (elements) {
Iterator<RenderElement> iter = getElementsByZIndex();
while (iter.hasNext()) {
//? if >=26.1 {
/*iter.next().extractRenderState(drawContext, 0, 0, 0);
*///?} else {
iter.next().render(drawContext, 0, 0, 0);
//?}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
//? if >=26.1 {
/*import net.minecraft.client.renderer.SubmitNodeCollector;
*///?}
import net.minecraft.world.phys.Vec3;
import com.jsmacrosce.doclet.DocletIgnore;
import com.jsmacrosce.jsmacros.api.math.Pos2D;
Expand Down Expand Up @@ -709,7 +712,11 @@ public Draw3D unregister() {
}

@DocletIgnore
//? if >=26.1 {
/*public void render(PoseStack poseStack, MultiBufferSource consumers, SubmitNodeCollector collector, float tickDelta) {
*///?} else {
public void render(PoseStack poseStack, MultiBufferSource consumers, float tickDelta) {
//?}
Camera camera = Minecraft.getInstance().gameRenderer.getMainCamera();
//? if >=1.21.11 {
/*Vec3 cameraPos = camera.position();
Expand All @@ -726,7 +733,11 @@ public void render(PoseStack poseStack, MultiBufferSource consumers, float tickD
Collections.sort(elements);

for (RenderElement3D<?> element : elements) {
//? if >=26.1 {
/*element.render(poseStack, consumers, collector, tickDelta);
*///?} else {
element.render(poseStack, consumers, tickDelta);
//?}
}
}

Expand Down
Loading