diff --git a/CHANGELOG.md b/CHANGELOG.md index 96e592bf1b..9172bf2d5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ # ChangeLog * fix stone ores having broken translations +* fix transfer + fix ldlib +* fix fluid slot overflow +* fix assembly line recipe handling diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java b/common/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java index 2e4719e7e1..32f7b2be34 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/machine/MachineCoverContainer.java @@ -178,7 +178,7 @@ private boolean onCoverDirty(CoverBehavior coverBehavior) { for (IRef ref : coverBehavior.getSyncStorage().getNonLazyFields()) { ref.update(); } - return coverBehavior.getSyncStorage().hasDirtyFields(); + return coverBehavior.getSyncStorage().hasDirtySyncFields() || coverBehavior.getSyncStorage().hasDirtyPersistedFields(); } return false; } diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java b/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java index a9d5b3f16f..4cca505034 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/machine/trait/NotifiableFluidTank.java @@ -66,6 +66,9 @@ public NotifiableFluidTank(MetaMachine machine, List storages, IO for (FluidStorage storage : this.storages) { storage.setOnContentsChanged(this::onContentsChanged); } + if (io == IO.IN) { + this.allowSameFluids = true; + } } public NotifiableFluidTank(MetaMachine machine, int slots, long capacity, IO io) { @@ -215,6 +218,36 @@ public boolean isFluidValid(int tank, @NotNull FluidStack stack) { return storages[tank].isFluidValid(stack); } + @Override + public long fill(FluidStack resource, boolean simulate, boolean notifyChanges) { + if (resource.isEmpty()) return 0; + long filled = 0; + FluidStorage existingStorage = null; + if (!allowSameFluids) { + for (var storage : storages) { + if (!storage.getFluid().isEmpty() && storage.getFluid().isFluidEqual(resource)) { + existingStorage = storage; + break; + } + } + } + if (existingStorage == null) { + for (int i = 0; i < getTanks(); i++) { + if (filled > 0 && !allowSameFluids) { + break; + } + filled += fill(i, resource.copy(resource.getAmount() - filled), simulate, notifyChanges); + if (filled == resource.getAmount()) break; + } + } else { + filled += existingStorage.fill(resource.copy(resource.getAmount() - filled), simulate, notifyChanges); + } + if (notifyChanges && filled > 0 && !simulate) { + onContentsChanged(); + } + return filled; + } + @Override public long fill(int tank, FluidStack resource, boolean simulate, boolean notifyChanges) { if (tank >= 0 && tank < storages.length && canCapInput()) { diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java b/common/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java index 31b2f10505..bbe0c9855b 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/pipenet/PipeCoverContainer.java @@ -171,7 +171,7 @@ public void setCoverAtSide(@Nullable CoverBehavior coverBehavior, Direction side @SuppressWarnings("unused") private boolean onCoverDirty(CoverBehavior coverBehavior) { - return coverBehavior != null && coverBehavior.getSyncStorage().hasDirtyFields(); + return coverBehavior != null && (coverBehavior.getSyncStorage().hasDirtySyncFields() || coverBehavior.getSyncStorage().hasDirtyPersistedFields()); } @SuppressWarnings("unused") diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/SizedIngredient.java b/common/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/SizedIngredient.java index 4781773052..4e98abdf5e 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/SizedIngredient.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/recipe/ingredient/SizedIngredient.java @@ -59,7 +59,11 @@ public static SizedIngredient create(TagKey tag, int amount) { public static SizedIngredient copy(Ingredient ingredient) { if (ingredient instanceof SizedIngredient sizedIngredient) { - return SizedIngredient.create(sizedIngredient.inner, sizedIngredient.amount); + var copied = SizedIngredient.create(sizedIngredient.inner, sizedIngredient.amount); + if (sizedIngredient.itemStacks != null) { + copied.itemStacks = Arrays.stream(sizedIngredient.itemStacks).map(ItemStack::copy).toArray(ItemStack[]::new); + } + return copied; } return SizedIngredient.create(ingredient); } diff --git a/common/src/main/java/com/gregtechceu/gtceu/api/syncdata/EnhancedFieldManagedStorage.java b/common/src/main/java/com/gregtechceu/gtceu/api/syncdata/EnhancedFieldManagedStorage.java index a32fa0564d..8541bf3b1b 100644 --- a/common/src/main/java/com/gregtechceu/gtceu/api/syncdata/EnhancedFieldManagedStorage.java +++ b/common/src/main/java/com/gregtechceu/gtceu/api/syncdata/EnhancedFieldManagedStorage.java @@ -2,11 +2,17 @@ import com.gregtechceu.gtceu.GTCEu; import com.lowdragmc.lowdraglib.LDLib; +import com.lowdragmc.lowdraglib.Platform; import com.lowdragmc.lowdraglib.syncdata.field.FieldManagedStorage; import com.lowdragmc.lowdraglib.syncdata.managed.IRef; +import net.minecraft.Util; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.function.BiFunction; +import java.util.function.Function; +import java.util.function.Supplier; /** * @author KilaBash @@ -32,6 +38,23 @@ public void init() { } } + final static BiFunction, Method> METHOD_CACHES = Util.memoize((rawField, clazz) -> { + var methodName = rawField.getAnnotation(UpdateListener.class).methodName(); + Method method = null; + while (clazz != null && method == null) { + try { + method = clazz.getDeclaredMethod(methodName, rawField.getType(), rawField.getType()); + method.setAccessible(true); + } catch (NoSuchMethodException ignored) { + } + clazz = clazz.getSuperclass(); + } + if (method == null) { + GTCEu.LOGGER.error("couldn't find the listener method {} for synced field {}", methodName, rawField.getName()); + } + return method; + }); + public void initEnhancedFeature() { for (IRef syncField : getSyncFields()) { var rawField = syncField.getKey().getRawField(); @@ -39,28 +62,15 @@ public void initEnhancedFeature() { addSyncUpdateListener(syncField.getKey(), enhancedManaged::scheduleRender); } if (rawField.isAnnotationPresent(UpdateListener.class)) { - var methodName = rawField.getAnnotation(UpdateListener.class).methodName(); - Method method = null; - Class clazz = enhancedManaged.getClass(); - while (clazz != null && method == null) { - try { - method = clazz.getDeclaredMethod(methodName, rawField.getType(), rawField.getType()); - method.setAccessible(true); - } catch (NoSuchMethodException ignored) { - } - clazz = clazz.getSuperclass(); - } + final var method = METHOD_CACHES.apply(rawField, enhancedManaged.getClass()); if (method != null) { - final Method finalMethod = method; addSyncUpdateListener(syncField.getKey(), (name, newValue, oldValue) -> { try { - finalMethod.invoke(enhancedManaged, newValue, oldValue); + method.invoke(enhancedManaged, newValue, oldValue); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }); - } else { - GTCEu.LOGGER.error("couldn't find the listener method {} for synced field {}", methodName, rawField.getName()); } } } diff --git a/settings.gradle b/settings.gradle index de0423b0a4..64a74eb3ce 100644 --- a/settings.gradle +++ b/settings.gradle @@ -57,7 +57,7 @@ dependencyResolutionManagement { def vineFlowerVersion = "1.+" def macheteVersion = "1.+" def configurationVersion = "2.2.0" - def ldLibVersion = "1.0.19.d" + def ldLibVersion = "1.0.20" def mixinextrasVersion = "0.2.0-rc.5" fabric {