From 85571964a8524f4f453f2ea8106b77147318cd86 Mon Sep 17 00:00:00 2001 From: Naz Date: Sat, 27 Dec 2025 17:01:40 +0800 Subject: [PATCH 1/5] Update to 26.1, migrate to Mojang mappings --- build.gradle | 26 +++++++------------ gradle.properties | 7 +++-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../team/reborn/energy/api/EnergyStorage.java | 12 ++++----- .../reborn/energy/api/EnergyStorageUtil.java | 2 +- .../energy/api/base/SimpleEnergyItem.java | 6 ++--- .../api/base/SimpleSidedEnergyContainer.java | 6 ++--- .../team/reborn/energy/impl/EnergyImpl.java | 18 ++++++------- .../impl/SimpleItemEnergyStorageImpl.java | 4 +-- src/main/resources/fabric.mod.json | 4 +-- .../team/reborn/energy/test/EnergyTests.java | 18 ++++++------- .../reborn/energy/test/TestBatteryItem.java | 12 ++++----- 12 files changed, 55 insertions(+), 62 deletions(-) diff --git a/build.gradle b/build.gradle index 6a9cecd..563803e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,7 @@ +import groovy.xml.XmlSlurper + plugins { - id 'fabric-loom' version '1.10-SNAPSHOT' + id 'net.fabricmc.fabric-loom' version '1.14-SNAPSHOT' id 'java' id 'maven-publish' } @@ -12,23 +14,15 @@ def ENV = System.getenv() group = "teamreborn" version = project.mod_version -loom { - addRemapConfiguration("testModImplementation") { - targetConfigurationName = "test" - onCompileClasspath = true - onRuntimeClasspath = true - } -} - dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" - modApi fabricApi.module("fabric-transfer-api-v1", project.fabric_version) + implementation "net.fabricmc:fabric-loader:${project.loader_version}" + + api fabricApi.module("fabric-transfer-api-v1", project.fabric_version) testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}" - testModImplementation fabricApi.module("fabric-registry-sync-v0", project.fabric_version) + testImplementation fabricApi.module("fabric-registry-sync-v0", project.fabric_version) } test { @@ -45,7 +39,7 @@ processResources { tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" - it.options.release = 21 + it.options.release = 25 } jar { @@ -54,8 +48,8 @@ jar { java { withSourcesJar() - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = JavaVersion.VERSION_25 + targetCompatibility = JavaVersion.VERSION_25 } publishing { diff --git a/gradle.properties b/gradle.properties index b8f97da..49fc859 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,9 +5,8 @@ mod_version=4.2.0 # Fabric Properties # check these on https://fabricmc.net/versions.html -minecraft_version=1.21.5-pre2 -yarn_mappings=1.21.5-pre2+build.6 -loader_version=0.16.10 +minecraft_version=26.1-snapshot-1 +loader_version=0.18.4 # Dependencies -fabric_version=0.119.0+1.21.5 \ No newline at end of file +fabric_version=0.140.2+26.1 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37f853b..23449a2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/src/main/java/team/reborn/energy/api/EnergyStorage.java b/src/main/java/team/reborn/energy/api/EnergyStorage.java index 5672435..cce3bfa 100644 --- a/src/main/java/team/reborn/energy/api/EnergyStorage.java +++ b/src/main/java/team/reborn/energy/api/EnergyStorage.java @@ -5,9 +5,9 @@ import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; -import net.minecraft.component.ComponentType; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.Direction; +import net.minecraft.core.Direction; +import net.minecraft.core.component.DataComponentType; +import net.minecraft.resources.Identifier; import org.jetbrains.annotations.Nullable; import team.reborn.energy.api.base.DelegatingEnergyStorage; import team.reborn.energy.api.base.SimpleEnergyItem; @@ -56,7 +56,7 @@ public interface EnergyStorage { * On the client thread (i.e. with a client world), contents of queried EnergyStorages are unreliable and should not be modified. */ BlockApiLookup SIDED = - BlockApiLookup.get(Identifier.of("teamreborn", "sided_energy"), EnergyStorage.class, Direction.class); + BlockApiLookup.get(Identifier.fromNamespaceAndPath("teamreborn", "sided_energy"), EnergyStorage.class, Direction.class); /** * Item access to energy storages. @@ -72,7 +72,7 @@ public interface EnergyStorage { * Returned APIs should behave the same regardless of the logical side. */ ItemApiLookup ITEM = - ItemApiLookup.get(Identifier.of("teamreborn", "energy"), EnergyStorage.class, ContainerItemContext.class); + ItemApiLookup.get(Identifier.fromNamespaceAndPath("teamreborn", "energy"), EnergyStorage.class, ContainerItemContext.class); /** * Always empty energy storage. @@ -86,7 +86,7 @@ public interface EnergyStorage { * Otherwise, do not query it or assume it exists. * Inter-mod energy interactions should happen using {@link #ITEM}. */ - ComponentType ENERGY_COMPONENT = Objects.requireNonNull(EnergyImpl.ENERGY_COMPONENT); + DataComponentType ENERGY_COMPONENT = Objects.requireNonNull(EnergyImpl.ENERGY_COMPONENT); /** * Return false if calling {@link #insert} will absolutely always return 0, or true otherwise or in doubt. diff --git a/src/main/java/team/reborn/energy/api/EnergyStorageUtil.java b/src/main/java/team/reborn/energy/api/EnergyStorageUtil.java index 316ed96..eb2a98f 100644 --- a/src/main/java/team/reborn/energy/api/EnergyStorageUtil.java +++ b/src/main/java/team/reborn/energy/api/EnergyStorageUtil.java @@ -4,7 +4,7 @@ import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; /** diff --git a/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java b/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java index 0a46bec..687a543 100644 --- a/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java +++ b/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java @@ -2,8 +2,8 @@ import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; -import net.minecraft.component.ComponentChanges; -import net.minecraft.item.ItemStack; +import net.minecraft.core.component.DataComponentPatch; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; import team.reborn.energy.api.EnergyStorage; import team.reborn.energy.impl.SimpleItemEnergyStorageImpl; @@ -97,7 +97,7 @@ static long getStoredEnergyUnchecked(ItemVariant variant) { return getStoredEnergyUnchecked(variant.getComponents()); } - static long getStoredEnergyUnchecked(ComponentChanges components) { + static long getStoredEnergyUnchecked(DataComponentPatch components) { @Nullable Optional energy = (Optional) components.get(EnergyStorage.ENERGY_COMPONENT); //noinspection OptionalAssignedToNull diff --git a/src/main/java/team/reborn/energy/api/base/SimpleSidedEnergyContainer.java b/src/main/java/team/reborn/energy/api/base/SimpleSidedEnergyContainer.java index cc4a267..420b74a 100644 --- a/src/main/java/team/reborn/energy/api/base/SimpleSidedEnergyContainer.java +++ b/src/main/java/team/reborn/energy/api/base/SimpleSidedEnergyContainer.java @@ -3,7 +3,7 @@ import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant; -import net.minecraft.util.math.Direction; +import net.minecraft.core.Direction; import org.jetbrains.annotations.Nullable; import team.reborn.energy.api.EnergyStorage; @@ -19,7 +19,7 @@ public abstract class SimpleSidedEnergyContainer extends SnapshotParticipant ENERGY_COMPONENT = ComponentType.builder() - .codec(nonNegativeLong()) - .packetCodec(PacketCodecs.VAR_LONG) + public static final DataComponentType ENERGY_COMPONENT = DataComponentType.builder() + .persistent(nonNegativeLong()) + .networkSynchronized(ByteBufCodecs.VAR_LONG) .build(); public static void init() { - Registry.register(Registries.DATA_COMPONENT_TYPE, Identifier.of("team_reborn_energy", "energy"), ENERGY_COMPONENT); + Registry.register(BuiltInRegistries.DATA_COMPONENT_TYPE, Identifier.fromNamespaceAndPath("team_reborn_energy", "energy"), ENERGY_COMPONENT); EnergyStorage.ITEM.registerFallback((stack, ctx) -> { if (stack.getItem() instanceof SimpleEnergyItem energyItem) { return SimpleEnergyItem.createStorage(ctx, energyItem.getEnergyCapacity(stack), energyItem.getEnergyMaxInput(stack), energyItem.getEnergyMaxOutput(stack)); diff --git a/src/main/java/team/reborn/energy/impl/SimpleItemEnergyStorageImpl.java b/src/main/java/team/reborn/energy/impl/SimpleItemEnergyStorageImpl.java index 5669a83..6d86f66 100644 --- a/src/main/java/team/reborn/energy/impl/SimpleItemEnergyStorageImpl.java +++ b/src/main/java/team/reborn/energy/impl/SimpleItemEnergyStorageImpl.java @@ -5,8 +5,8 @@ import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import team.reborn.energy.api.EnergyStorage; import team.reborn.energy.api.base.DelegatingEnergyStorage; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 3a32bfb..a0f68c5 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -22,8 +22,8 @@ ] }, "depends": { - "java": ">=21", - "minecraft": ">=1.21.5-", + "java": ">=25", + "minecraft": ">=26.1-", "fabric-transfer-api-v1": ">=5.1.0" } } diff --git a/src/test/java/team/reborn/energy/test/EnergyTests.java b/src/test/java/team/reborn/energy/test/EnergyTests.java index 30c8d9c..d9bfcbd 100644 --- a/src/test/java/team/reborn/energy/test/EnergyTests.java +++ b/src/test/java/team/reborn/energy/test/EnergyTests.java @@ -5,13 +5,13 @@ import net.fabricmc.fabric.api.transfer.v1.storage.base.SingleVariantStorage; import net.fabricmc.fabric.api.transfer.v1.transaction.Transaction; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; -import net.minecraft.Bootstrap; import net.minecraft.SharedConstants; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.registry.Registries; -import net.minecraft.registry.Registry; -import net.minecraft.util.Identifier; +import net.minecraft.core.Registry; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; +import net.minecraft.server.Bootstrap; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import team.reborn.energy.api.EnergyStorage; @@ -28,12 +28,12 @@ public class EnergyTests { @BeforeAll public static void setup() { - SharedConstants.createGameVersion(); - Bootstrap.initialize(); + SharedConstants.tryDetectVersion(); + Bootstrap.bootStrap(); EnergyImpl.init(); item = new TestBatteryItem(60, 50, 50); - Registry.register(Registries.ITEM, Identifier.of("energy_test", "battery"), item); + Registry.register(BuiltInRegistries.ITEM, Identifier.fromNamespaceAndPath("energy_test", "battery"), item); } @Test diff --git a/src/test/java/team/reborn/energy/test/TestBatteryItem.java b/src/test/java/team/reborn/energy/test/TestBatteryItem.java index e8340bf..40e9cd1 100644 --- a/src/test/java/team/reborn/energy/test/TestBatteryItem.java +++ b/src/test/java/team/reborn/energy/test/TestBatteryItem.java @@ -1,17 +1,17 @@ package team.reborn.energy.test; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.registry.RegistryKey; -import net.minecraft.registry.RegistryKeys; -import net.minecraft.util.Identifier; +import net.minecraft.core.registries.Registries; +import net.minecraft.resources.Identifier; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import team.reborn.energy.api.base.SimpleEnergyItem; public class TestBatteryItem extends Item implements SimpleEnergyItem { private final long capacity, maxInput, maxOutput; public TestBatteryItem(long capacity, long maxInput, long maxOutput) { - super(new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, Identifier.of("energy_test", "battery")))); + super(new Item.Properties().setId(ResourceKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath("energy_test", "battery")))); this.capacity = capacity; this.maxInput = maxInput; this.maxOutput = maxOutput; From 7313b77b078963a87fe4270c6627c615fcdb8650 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 1 Jan 2026 08:03:29 +0800 Subject: [PATCH 2/5] Update Fabric API to 0.140.3+26.1 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 49fc859..61fa7e4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,4 @@ minecraft_version=26.1-snapshot-1 loader_version=0.18.4 # Dependencies -fabric_version=0.140.2+26.1 \ No newline at end of file +fabric_version=0.140.3+26.1 \ No newline at end of file From 5b98c3e2458d44fad091179eb5748f78a12f8373 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 1 Jan 2026 08:03:57 +0800 Subject: [PATCH 3/5] Use JDK 25 on Actions --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e7a8589..331b9ad 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,7 +5,7 @@ jobs: build: runs-on: ubuntu-24.04 container: - image: mcr.microsoft.com/openjdk/jdk:21-ubuntu + image: mcr.microsoft.com/openjdk/jdk:25-ubuntu options: --user root steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 46bea5a..1ae8a42 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,7 @@ jobs: build: runs-on: ubuntu-24.04 container: - image: mcr.microsoft.com/openjdk/jdk:21-ubuntu + image: mcr.microsoft.com/openjdk/jdk:25-ubuntu options: --user root steps: - uses: actions/checkout@v4 From a3d150df149ff10985cecc7a62781f95a1b83d7b Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 1 Jan 2026 08:06:28 +0800 Subject: [PATCH 4/5] Fix compile error with Fabric API update --- .../reborn/energy/api/base/SimpleEnergyItem.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java b/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java index 687a543..c0a2431 100644 --- a/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java +++ b/src/main/java/team/reborn/energy/api/base/SimpleEnergyItem.java @@ -2,6 +2,7 @@ import net.fabricmc.fabric.api.transfer.v1.context.ContainerItemContext; import net.fabricmc.fabric.api.transfer.v1.item.ItemVariant; +import net.minecraft.core.component.DataComponentMap; import net.minecraft.core.component.DataComponentPatch; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.Nullable; @@ -97,15 +98,8 @@ static long getStoredEnergyUnchecked(ItemVariant variant) { return getStoredEnergyUnchecked(variant.getComponents()); } - static long getStoredEnergyUnchecked(DataComponentPatch components) { - @Nullable Optional energy = (Optional) components.get(EnergyStorage.ENERGY_COMPONENT); - - //noinspection OptionalAssignedToNull - if (energy != null) { - return energy.orElse(0L); - } - - return 0; + static long getStoredEnergyUnchecked(DataComponentMap components) { + return components.getOrDefault(EnergyStorage.ENERGY_COMPONENT, 0L); } /** From cc0b0400ed7afd84be2686c92284e2e6f7c2c083 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 1 Jan 2026 08:09:43 +0800 Subject: [PATCH 5/5] Update README to match Mojang mappings --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bda5be9..97172c1 100644 --- a/README.md +++ b/README.md @@ -43,16 +43,16 @@ public class MyBlockEntity extends BlockEntity { public final SimpleEnergyStorage energyStorage = new SimpleEnergyStorage(CAPACITY, MAX_INSERT, MAX_EXTRACT) { @Override protected void onFinalCommit() { - markDirty(); + setChanged(); } }; // Use the energy internally, for example in tick() public void tick() { - if (!world.isClient && energyStorage.amount >= 10) { + if (!level.isClientSide() && energyStorage.amount >= 10) { energyStorage.amount -= 10; // do something with the 10 energy we just used. - markDirty(); + setChanged(); } } @@ -78,10 +78,10 @@ EnergyStorage maybeStorage = EnergyStorage.SIDED.find(world, pos, direction); Get an adjacent energy storage: ```groovy // Known things -World world; BlockPos currentPos; Direction adjacentDirection; +Level level; BlockPos currentPos; Direction adjacentDirection; // Get adjacent energy storage, or null if there is none @Nullable -EnergyStorage maybeStorage = EnergyStorage.SIDED.find(world, currentPos.offset(adjacentDirection), adjacentDirection.getOpposite()); +EnergyStorage maybeStorage = EnergyStorage.SIDED.find(level, currentPos.relative(adjacentDirection), adjacentDirection.getOpposite()); ``` Move energy between two storages: ```groovy