Skip to content

Commit 96cafdf

Browse files
committed
Replaced empty AE keys with null instead since the .of function returns null anyways when an empty stack is passed.
Maybe fixed some issues with minecolonies, needs some testing from a user
1 parent b39cdcf commit 96cafdf

9 files changed

Lines changed: 32 additions & 16 deletions

File tree

build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,6 @@ dependencies {
276276
runtimeOnly "me.shedaniel.cloth:cloth-config-neoforge:${cloth_config_version}"
277277
runtimeOnly "curse.maven:powah-633483:${powah_version}"
278278

279-
testImplementation "org.junit.jupiter:junit-jupiter-api:${junit_version}"
280-
testImplementation "org.junit.jupiter:junit-jupiter-params:${junit_version}"
281-
testImplementation "org.hamcrest:hamcrest:${hamcrest_version}"
282-
testImplementation "org.jetbrains.kotlin:kotlin-reflect:${kotlin_version}"
283-
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:${kotlinx_coroutines_version}"
284279
testModImplementation sourceSets.main.output
285280

286281
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junit_version}"

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod_id=advancedperipherals
1010
mod_version=0.7.51b
1111
minecraft_version=1.21.1
1212
mod_artifact_suffix=
13-
neo_version=21.1.140
13+
neo_version=21.1.174
1414
parchment_minecraft_version=1.21.1
1515
parchment_mappings_version=2024.11.17
1616
loader_version=4

src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/AEApi.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,14 @@ public static Pair<Long, AEItemKey> findAEStackFromFilter(MEStorage monitor, @Nu
8989
}
9090

9191
if (crafting == null)
92-
return Pair.of(0L, AEItemKey.of(ItemStack.EMPTY));
92+
return Pair.of(0L, null);
9393

9494
for (var temp : crafting.getCraftables(param -> true)) {
9595
if (temp instanceof AEItemKey key && filter.test(key.toStack()))
9696
return Pair.of(0L, key);
9797
}
9898

99-
return Pair.of(0L, AEItemKey.of(ItemStack.EMPTY));
99+
return Pair.of(0L, null);
100100
}
101101

102102
@NotNull
@@ -112,14 +112,14 @@ public static Pair<Long, AEFluidKey> findAEFluidFromFilter(MEStorage monitor, @N
112112
}
113113

114114
if (crafting == null)
115-
return Pair.of(0L, AEFluidKey.of(FluidStack.EMPTY));
115+
return Pair.of(0L, null);
116116

117117
for (var temp : crafting.getCraftables(param -> true)) {
118118
if (temp instanceof AEFluidKey key && filter.test(key.toStack(1)))
119119
return Pair.of(0L, key);
120120
}
121121

122-
return Pair.of(0L, AEFluidKey.of(FluidStack.EMPTY));
122+
return Pair.of(0L, null);
123123
}
124124

125125
@NotNull
@@ -135,14 +135,14 @@ public static Pair<Long, MekanismKey> findAEChemicalFromFilter(MEStorage monitor
135135
}
136136

137137
if (crafting == null)
138-
return Pair.of(0L, MekanismKey.of(ChemicalStack.EMPTY));
138+
return Pair.of(0L, null);
139139

140140
for (var temp : crafting.getCraftables(param -> true)) {
141141
if (temp instanceof MekanismKey key && filter.test(key.getStack()))
142142
return Pair.of(0L, key);
143143
}
144144

145-
return Pair.of(0L, MekanismKey.of(ChemicalStack.EMPTY));
145+
return Pair.of(0L, null);
146146
}
147147

148148
/**

src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEChemicalHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public ChemicalStack insertChemical(int tank, ChemicalStack resource, @NotNull A
4646
@Override
4747
public ChemicalStack extractChemical(ChemicalFilter filter, long count, Action simulate) {
4848
Pair<Long, MekanismKey> chemicalKey = AEApi.findAEChemicalFromFilter(storageMonitor, null, filter);
49-
if (chemicalKey.getRight().getStack().isEmpty())
49+
if (chemicalKey.getRight() == null)
5050
return ChemicalStack.EMPTY;
5151

5252
ChemicalStack extracted = chemicalKey.getRight().getStack();

src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEFluidHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public int fill(FluidStack resource, FluidAction action) {
4242
@Override
4343
public FluidStack drain(FluidFilter filter, FluidAction simulate) {
4444
Pair<Long, AEFluidKey> fluidKey = AEApi.findAEFluidFromFilter(storageMonitor, null, filter);
45-
if (fluidKey.getRight().toStack(0).isEmpty())
45+
if (fluidKey.getRight() == null)
4646
return FluidStack.EMPTY;
4747
long extracted = storageMonitor.extract(fluidKey.getRight(), filter.getCount(), simulate == FluidAction.SIMULATE ? Actionable.SIMULATE : Actionable.MODULATE, actionSource);
4848
return new FluidStack(fluidKey.getRight().getFluid(), (int) Math.min(extracted, Integer.MAX_VALUE));

src/main/java/de/srendi/advancedperipherals/common/addons/appliedenergistics/MEItemHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate
4242
@Override
4343
public ItemStack extractItem(ItemFilter filter, int count, boolean simulate) {
4444
Pair<Long, AEItemKey> itemKey = AEApi.findAEStackFromFilter(storageMonitor, null, filter);
45-
if (itemKey.getRight().toStack().isEmpty())
45+
if (itemKey.getRight() == null)
4646
return ItemStack.EMPTY;
4747
long extracted = storageMonitor.extract(itemKey.getRight(), count, simulate ? Actionable.SIMULATE : Actionable.MODULATE, actionSource);
4848
// Safe to cast here, the amount will never be higher than 64

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/peripheral/ColonyPeripheral.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ public final Object getRequests() throws LuaException {
276276
map.put("state", request.getState().toString());
277277
map.put("count", deliverableRequest.getCount());
278278
map.put("minCount", deliverableRequest.getMinimumCount());
279-
map.put("items", request.getDisplayStacks().stream().map(LuaConverter::itemStackToObject).collect(Collectors.toList()));
279+
map.put("items", request.getDisplayStacks().stream().map(item -> LuaConverter.itemStackToObject(item, getLevel())).collect(Collectors.toList()));
280280
map.put("target", request.getRequester().getRequesterDisplayName(requestManager, request).getString());
281281
result.add(map);
282282
});

src/main/java/de/srendi/advancedperipherals/common/util/DataComponentUtil.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
import net.minecraft.nbt.NbtOps;
55
import net.minecraft.nbt.Tag;
66
import net.minecraft.resources.RegistryOps;
7+
import net.minecraft.world.level.Level;
78
import net.neoforged.neoforge.server.ServerLifecycleHooks;
89

910
public class DataComponentUtil {
1011

12+
public static Tag toNbt(DataComponentPatch patch, Level level) {
13+
return DataComponentPatch.CODEC.encodeStart(RegistryOps.create(NbtOps.INSTANCE, level.registryAccess()), patch).getOrThrow();
14+
}
15+
1116
public static Tag toNbt(DataComponentPatch patch) {
1217
return DataComponentPatch.CODEC.encodeStart(RegistryOps.create(NbtOps.INSTANCE, ServerLifecycleHooks.getCurrentServer().registryAccess()), patch).getOrThrow();
1318
}

src/main/java/de/srendi/advancedperipherals/common/util/LuaConverter.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import net.minecraft.world.entity.animal.Animal;
2020
import net.minecraft.world.item.Item;
2121
import net.minecraft.world.item.ItemStack;
22+
import net.minecraft.world.level.Level;
2223
import net.minecraft.world.level.block.state.properties.Property;
2324
import net.minecraft.world.level.material.Fluid;
2425
import net.neoforged.neoforge.common.IShearable;
@@ -125,6 +126,21 @@ public static Map<String, Object> itemStackToObject(@NotNull ItemStack stack) {
125126
return properties;
126127
}
127128

129+
public static Map<String, Object> itemStackToObject(@NotNull ItemStack stack, Level level) {
130+
if (stack.isEmpty()) {
131+
return null;
132+
}
133+
Map<String, Object> properties = itemToObject(stack.getItem());
134+
DataComponentPatch components = stack.getComponentsPatch();
135+
properties.put("count", stack.getCount());
136+
properties.put("displayName", stack.getDisplayName().getString());
137+
properties.put("maxStackSize", stack.getMaxStackSize());
138+
properties.put("components", NBTUtil.toLua(DataComponentUtil.toNbt(components, level)));
139+
properties.put("fingerprint", ItemUtil.getFingerprint(stack));
140+
return properties;
141+
}
142+
143+
128144
public static Map<String, Object> fluidStackToObject(@NotNull FluidStack stack) {
129145
if (stack.isEmpty()) {
130146
return null;

0 commit comments

Comments
 (0)