Skip to content

Commit

Permalink
fixes (#495)
Browse files Browse the repository at this point in the history
* fix transfer + fix ldlib

* fix fluid slot overflow

* fix assembly line recipe handling

* add cache for enhancedfieldmanagedstorage

* version 1.0.13.e
  • Loading branch information
Yefancy authored Oct 28, 2023
1 parent 9815cdf commit 068b9b5
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 26 deletions.
9 changes: 3 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# ChangeLog

* fix tools only accepting digger enchantments
* fix stone, netherrack, hay being craftable to 9 dust in a crafting table
* fix machines sometimes crashing when auto-output is toggled rapidly, resulting in it being enabled but no output side being set
* fix SoundEntryProvider always placing the JSON in /assets/gtceu/sounds.json
* add material tooltips for non-GT items
* add KJS binding for ChemicalHelper
* fix transfer + fix ldlib
* fix fluid slot overflow
* fix assembly line recipe handling
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public NotifiableFluidTank(MetaMachine machine, List<FluidStorage> 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) {
Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public static SizedIngredient create(TagKey<Item> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,35 +38,39 @@ public void init() {
}
}

final static BiFunction<Field, Class<?>, 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();
if (rawField.isAnnotationPresent(RequireRerender.class)) {
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());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs = -Xmx6G
# Mod Info
mod_id = gtceu
mod_name = GregTech
mod_version = 1.0.13.d
mod_version = 1.0.13.e
mod_description = GregTech CE Unofficial, ported from 1.12.2
mod_license = LGPL-3.0 license
mod_url = https://github.com/GregTechCEu/GregTech-Modern/
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencyResolutionManagement {
def architecturyLoomVersion = "1.0-SNAPSHOT"
def vineFlowerVersion = "1.+"
def macheteVersion = "1.+"
def ldLibVersion = "1.0.19.d"
def ldLibVersion = "1.0.20"

fabric {
def parchment = version("parchment", parchmentVersion)
Expand Down

0 comments on commit 068b9b5

Please sign in to comment.