diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index fd96ee6..857b9e5 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v4 - name: Validate Gradle wrapper - uses: gradle/actions/wrapper-validation@v3 + uses: gradle/actions/wrapper-validation@v4 - name: Setup JDK 21 uses: actions/setup-java@v4 diff --git a/.github/workflows/commit.yml b/.github/workflows/commit.yml index b8f8372..274509d 100644 --- a/.github/workflows/commit.yml +++ b/.github/workflows/commit.yml @@ -12,7 +12,7 @@ jobs: uses: actions/checkout@v4 - name: Validate Gradle wrapper - uses: gradle/actions/wrapper-validation@v3 + uses: gradle/actions/wrapper-validation@v4 - name: Setup JDK 21 uses: actions/setup-java@v4 diff --git a/.github/workflows/pr_check.yml b/.github/workflows/pr_check.yml index 92c52f8..c197ba2 100644 --- a/.github/workflows/pr_check.yml +++ b/.github/workflows/pr_check.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v4 - name: Validate Gradle wrapper - uses: gradle/actions/wrapper-validation@v3 + uses: gradle/actions/wrapper-validation@v4 - name: Setup JDK 21 uses: actions/setup-java@v4 diff --git a/build.gradle.kts b/build.gradle.kts index 98bf834..b1040c7 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -47,7 +47,7 @@ plugins { id("fabric-loom") version("1.7-SNAPSHOT") id("org.cadixdev.licenser") version("0.6.1") id("org.ajoberstar.grgit") version("5.2.2") - id("dev.galacticraft.mojarn") version("0.4.0+9") + id("dev.galacticraft.mojarn") version("0.4.0+10") } group = "dev.galacticraft" diff --git a/gradle.properties b/gradle.properties index 1d486fe..731b8d6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,18 +6,18 @@ mod.name=MachineLib mod.version=0.7.0 # Minecraft and Fabric Loader -minecraft.version=1.21 +minecraft.version=1.21.1 loader.version=0.15.11 -yarn.build=8 +yarn.build=3 # Mod Dependencies badpackets.version=0.8.1 energy.version=4.1.0 -fabric.version=0.100.6+1.21 +fabric.version=0.102.1+1.21.1 # Optional Mod Dependencies -cloth.config.version=15.0.127 +cloth.config.version=15.0.130 modmenu.version=11.0.1 -rei.version=16.0.729 -architectury.version=13.0.3 -wthit.version=12.2.2 +rei.version=16.0.754 +architectury.version=13.0.6 +wthit.version=12.3.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e644113..a4b76b9 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8a1f6b9..2b18997 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,7 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=a4b4158601f8636cdeeab09bd76afb640030bb5b144aafe261a5e8af027dc612 -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionSha256Sum=5b9c5eb3f9fc2c94abaea57d90bd78747ca117ddbbf96c859d3741181a12bf2a +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index b740cf1..f5feea6 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -84,7 +86,8 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum diff --git a/gradlew.bat b/gradlew.bat index 25da30d..9d21a21 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,6 +13,8 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem @if "%DEBUG%"=="" @echo off @rem ########################################################################## diff --git a/src/main/java/dev/galacticraft/machinelib/api/compat/transfer/ExposedEnergyStorage.java b/src/main/java/dev/galacticraft/machinelib/api/compat/transfer/ExposedEnergyStorage.java index 1435843..1c8a816 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/compat/transfer/ExposedEnergyStorage.java +++ b/src/main/java/dev/galacticraft/machinelib/api/compat/transfer/ExposedEnergyStorage.java @@ -22,6 +22,7 @@ package dev.galacticraft.machinelib.api.compat.transfer; +import dev.galacticraft.machinelib.api.storage.MachineEnergyStorage; import dev.galacticraft.machinelib.impl.storage.exposed.ExposedEnergyStorageImpl; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -40,7 +41,7 @@ public interface ExposedEnergyStorage extends EnergyStorage { * @return A new exposed energy storage. */ @Contract("_, _, _ -> new") - static @NotNull ExposedEnergyStorage create(@NotNull EnergyStorage parent, long maxInsertion, long maxExtraction) { + static @NotNull ExposedEnergyStorage create(@NotNull MachineEnergyStorage parent, long maxInsertion, long maxExtraction) { return new ExposedEnergyStorageImpl(parent, maxInsertion, maxExtraction); } } diff --git a/src/main/java/dev/galacticraft/machinelib/api/storage/MachineEnergyStorage.java b/src/main/java/dev/galacticraft/machinelib/api/storage/MachineEnergyStorage.java index 38360bd..4fb8dad 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/storage/MachineEnergyStorage.java +++ b/src/main/java/dev/galacticraft/machinelib/api/storage/MachineEnergyStorage.java @@ -34,6 +34,7 @@ import net.fabricmc.fabric.api.transfer.v1.storage.StoragePreconditions; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.minecraft.nbt.LongTag; +import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -204,10 +205,15 @@ public interface MachineEnergyStorage extends EnergyStorage, Serializable> extends Iterable, MutableModifiable, SlottedStorageAccess, Serializable, DeltaPacketSerializable, PacketSerializable { /** - * Set the listener for this storage. This listener will be called whenever the storage is modified. + * Set the parent for this storage. This parent will be notified whenever the storage is modified. * - * @param listener the listener to set. + * @param parent the parent of this storage. */ - void setListener(Runnable listener); + void setParent(BlockEntity parent); + + boolean isValid(); /** * Create an exposed storage for this storage. diff --git a/src/main/java/dev/galacticraft/machinelib/api/storage/slot/ResourceSlot.java b/src/main/java/dev/galacticraft/machinelib/api/storage/slot/ResourceSlot.java index b736d2d..16361b2 100644 --- a/src/main/java/dev/galacticraft/machinelib/api/storage/slot/ResourceSlot.java +++ b/src/main/java/dev/galacticraft/machinelib/api/storage/slot/ResourceSlot.java @@ -47,6 +47,11 @@ * @see StorageAccess */ public interface ResourceSlot extends StorageAccess, MutableModifiable, Serializable, PacketSerializable { + /** + * {@return whether this slot should still be interacted with} + */ + boolean isValid(); + /** * {@return the way this slot is allowed to be interacted with} * Governs in-world (block-to-block) and player (menu) interactions. diff --git a/src/main/java/dev/galacticraft/machinelib/impl/compat/transfer/ExposedSlotImpl.java b/src/main/java/dev/galacticraft/machinelib/impl/compat/transfer/ExposedSlotImpl.java index 8763bd2..0fd6a1d 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/compat/transfer/ExposedSlotImpl.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/compat/transfer/ExposedSlotImpl.java @@ -50,24 +50,24 @@ public ExposedSlotImpl(@NotNull ResourceSlot slot, @NotNull ResourceFl @Override public long insert(Variant variant, long maxAmount, TransactionContext transaction) { - return this.insertion && this.slot.getFilter().test(variant.getObject(), variant.getComponents()) ? + return this.supportsInsertion() && this.slot.getFilter().test(variant.getObject(), variant.getComponents()) ? this.slot.insert(variant.getObject(), variant.getComponents(), maxAmount, transaction) : 0; } @Override public long extract(Variant variant, long maxAmount, TransactionContext transaction) { - return this.extraction ? this.slot.extract(variant.getObject(), variant.getComponents(), maxAmount, transaction) : 0; + return this.supportsExtraction() ? this.slot.extract(variant.getObject(), variant.getComponents(), maxAmount, transaction) : 0; } @Override public boolean supportsInsertion() { - return this.insertion; + return this.insertion && this.slot.isValid() ; } @Override public boolean supportsExtraction() { - return this.extraction; + return this.extraction && this.slot.isValid() ; } @Override diff --git a/src/main/java/dev/galacticraft/machinelib/impl/compat/transfer/ExposedStorageImpl.java b/src/main/java/dev/galacticraft/machinelib/impl/compat/transfer/ExposedStorageImpl.java index a06ee7c..8d192de 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/compat/transfer/ExposedStorageImpl.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/compat/transfer/ExposedStorageImpl.java @@ -44,6 +44,7 @@ public ExposedStorageImpl(ResourceStorage storage, ExposedSlot slot : this.slots) { if (slot.supportsInsertion()) { return true; @@ -54,6 +55,7 @@ public boolean supportsInsertion() { @Override public boolean supportsExtraction() { + if (!this.storage.isValid()) return false; for (ExposedSlot slot : this.slots) { if (slot.supportsExtraction()) { return true; @@ -64,6 +66,7 @@ public boolean supportsExtraction() { @Override public long insert(Variant variant, long maxAmount, TransactionContext transaction) { + if (!this.storage.isValid()) return 0; long requested = maxAmount; for (ExposedSlot slot : this.slots) { if (maxAmount == 0) return requested; @@ -74,6 +77,7 @@ public long insert(Variant variant, long maxAmount, TransactionContext transacti @Override public long extract(Variant variant, long maxAmount, TransactionContext transaction) { + if (!this.storage.isValid()) return 0; long requested = maxAmount; for (ExposedSlot slot : this.slots) { if (maxAmount == 0) return requested; diff --git a/src/main/java/dev/galacticraft/machinelib/impl/storage/EmptyMachineEnergyStorage.java b/src/main/java/dev/galacticraft/machinelib/impl/storage/EmptyMachineEnergyStorage.java index f64e87d..12e316c 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/storage/EmptyMachineEnergyStorage.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/storage/EmptyMachineEnergyStorage.java @@ -27,6 +27,7 @@ import io.netty.buffer.ByteBuf; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.minecraft.nbt.LongTag; +import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import team.reborn.energy.api.EnergyStorage; @@ -138,7 +139,12 @@ public long externalExtractionRate() { } @Override - public void setListener(Runnable listener) { + public void setParent(BlockEntity parent) { + } + + @Override + public boolean isValid() { + return true; } @Override diff --git a/src/main/java/dev/galacticraft/machinelib/impl/storage/MachineEnergyStorageImpl.java b/src/main/java/dev/galacticraft/machinelib/impl/storage/MachineEnergyStorageImpl.java index 21df195..e0911eb 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/storage/MachineEnergyStorageImpl.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/storage/MachineEnergyStorageImpl.java @@ -29,6 +29,7 @@ import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.fabricmc.fabric.api.transfer.v1.transaction.base.SnapshotParticipant; import net.minecraft.nbt.LongTag; +import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,7 +42,7 @@ public final class MachineEnergyStorageImpl extends SnapshotParticipant im private final long maxOutput; private final @Nullable EnergyStorage[] exposedStorages = new EnergyStorage[3]; public long amount = 0; - private Runnable listener; + private BlockEntity parent; public MachineEnergyStorageImpl(long capacity, long maxInput, long maxOutput) { this.capacity = capacity; @@ -199,8 +200,13 @@ public long externalExtractionRate() { } @Override - public void setListener(Runnable listener) { - this.listener = listener; + public void setParent(BlockEntity parent) { + this.parent = parent; + } + + @Override + public boolean isValid() { + return this.parent == null || !this.parent.isRemoved(); } @Override @@ -235,7 +241,7 @@ public long getModifications() { } private void markModified() { - if (this.listener != null) this.listener.run(); + if (this.parent != null) this.parent.setChanged(); } @Override diff --git a/src/main/java/dev/galacticraft/machinelib/impl/storage/ResourceStorageImpl.java b/src/main/java/dev/galacticraft/machinelib/impl/storage/ResourceStorageImpl.java index 4cced0c..05d6f14 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/storage/ResourceStorageImpl.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/storage/ResourceStorageImpl.java @@ -29,13 +29,14 @@ import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import net.minecraft.nbt.ListTag; import net.minecraft.network.RegistryFriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntity; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public abstract class ResourceStorageImpl> extends BaseSlottedStorage implements ResourceStorage, TransactionContext.CloseCallback { private final LongList transactions = new LongArrayList(); private long modifications = 1; - private Runnable listener; + private @Nullable BlockEntity parent; public ResourceStorageImpl(@NotNull Slot @NotNull [] slots) { super(slots); @@ -45,8 +46,13 @@ public ResourceStorageImpl(@NotNull Slot @NotNull [] slots) { } @Override - public void setListener(Runnable listener) { - this.listener = listener; + public void setParent(@Nullable BlockEntity parent) { + this.parent = parent; + } + + @Override + public boolean isValid() { + return this.parent == null || !this.parent.isRemoved(); } @Override @@ -57,7 +63,7 @@ public long getModifications() { @Override public void markModified() { this.modifications++; - if (this.listener != null) this.listener.run(); + if (this.parent != null) this.parent.setChanged(); } @Override @@ -92,7 +98,7 @@ public void onClose(TransactionContext transaction, TransactionContext.Result re this.transactions.clear(); transaction.addOuterCloseCallback((res) -> { assert res.wasCommitted(); - if (this.listener != null) this.listener.run(); + if (this.parent != null) this.parent.setChanged(); }); } } diff --git a/src/main/java/dev/galacticraft/machinelib/impl/storage/exposed/ExposedEnergyStorageImpl.java b/src/main/java/dev/galacticraft/machinelib/impl/storage/exposed/ExposedEnergyStorageImpl.java index 52e6f6c..62e1cdf 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/storage/exposed/ExposedEnergyStorageImpl.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/storage/exposed/ExposedEnergyStorageImpl.java @@ -23,6 +23,7 @@ package dev.galacticraft.machinelib.impl.storage.exposed; import dev.galacticraft.machinelib.api.compat.transfer.ExposedEnergyStorage; +import dev.galacticraft.machinelib.api.storage.MachineEnergyStorage; import net.fabricmc.fabric.api.transfer.v1.transaction.TransactionContext; import org.jetbrains.annotations.NotNull; import team.reborn.energy.api.EnergyStorage; @@ -35,16 +36,16 @@ * @param maxExtraction The maximum amount of energy that can be extracted in one transaction. * @see EnergyStorage */ -public record ExposedEnergyStorageImpl(@NotNull EnergyStorage parent, long maxInsertion, +public record ExposedEnergyStorageImpl(@NotNull MachineEnergyStorage parent, long maxInsertion, long maxExtraction) implements ExposedEnergyStorage { @Override public boolean supportsInsertion() { - return this.maxInsertion > 0; + return this.parent.isValid() && this.maxInsertion > 0; } @Override public long insert(long maxAmount, TransactionContext transaction) { - if (this.maxInsertion > 0) { + if (this.supportsInsertion()) { return this.parent.insert(Math.min(this.maxInsertion, maxAmount), transaction); } return 0; @@ -52,12 +53,12 @@ public long insert(long maxAmount, TransactionContext transaction) { @Override public boolean supportsExtraction() { - return this.maxExtraction > 0; + return this.parent.isValid() && this.maxExtraction > 0; } @Override public long extract(long maxAmount, TransactionContext transaction) { - if (this.maxExtraction > 0) { + if (this.supportsExtraction()) { return this.parent.extract(Math.min(this.maxExtraction, maxAmount), transaction); } return 0; diff --git a/src/main/java/dev/galacticraft/machinelib/impl/storage/slot/ResourceSlotImpl.java b/src/main/java/dev/galacticraft/machinelib/impl/storage/slot/ResourceSlotImpl.java index 2cf7543..4644f2f 100644 --- a/src/main/java/dev/galacticraft/machinelib/impl/storage/slot/ResourceSlotImpl.java +++ b/src/main/java/dev/galacticraft/machinelib/impl/storage/slot/ResourceSlotImpl.java @@ -60,6 +60,11 @@ protected ResourceSlotImpl(TransferType transferType, ResourceFilter e this.capacity = capacity; } + @Override + public boolean isValid() { + return this.parent == null || this.parent.isValid(); + } + @Override public TransferType transferMode() { return this.transferType;