Skip to content

Commit 7f51d3d

Browse files
committed
replace some nbt data components to map
1 parent 9c6b73e commit 7f51d3d

17 files changed

Lines changed: 249 additions & 211 deletions

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public static List<Pair<Long, MekanismKey>> findAEChemicalsFromFilter(MEStorage
192192
@NotNull
193193
public static Pair<Pair<EncodedPatternItem<?>, IPatternDetails>, String> findPatternFromFilters(IGrid grid, Level level, @Nullable GenericFilter<?> inputFilter, @Nullable GenericFilter<?> outputFilter) {
194194
for (Pair<EncodedPatternItem<?>, IPatternDetails> pattern : getPatterns(grid, level)) {
195-
IPatternDetails patternDetails = pattern.getRight();
195+
IPatternDetails patternDetails = pattern.right();
196196
if (patternDetails.getInputs().length == 0)
197197
continue;
198198
if (patternDetails.getOutputs().isEmpty())
@@ -227,7 +227,7 @@ public static Pair<Pair<EncodedPatternItem<?>, IPatternDetails>, String> findPat
227227
}
228228

229229
if (inputMatch && outputMatch)
230-
return Pair.of(Pair.of(pattern.getLeft(), patternDetails), null);
230+
return Pair.of(Pair.of(pattern.left(), patternDetails), null);
231231
}
232232

233233
return Pair.of(null, StatusConstants.NOT_FOUND.toString());
@@ -351,16 +351,16 @@ private static Class<? extends PatternContainer> tryCastMachineToContainer(Class
351351
}
352352

353353
public static <T extends AEKey> Map<String, Object> parseAeStack(Pair<Long, T> stack, @Nullable ICraftingService service) {
354-
if (stack.getRight() == null)
354+
if (stack.right() == null)
355355
return null;
356-
if (stack.getRight() instanceof AEItemKey itemKey)
357-
return parseItemStack(Pair.of(stack.getLeft(), itemKey), service);
358-
if (stack.getRight() instanceof AEFluidKey fluidKey)
359-
return parseFluidStack(Pair.of(stack.getLeft(), fluidKey), service);
360-
if (APAddon.APP_MEKANISTICS.isLoaded() && (stack.getRight() instanceof MekanismKey gasKey))
361-
return parseChemStack(Pair.of(stack.getLeft(), gasKey), service);
362-
363-
AdvancedPeripherals.debug("Could not create table from unknown stack " + stack.getRight().getClass() + " - Report this to the maintainer of ap", org.apache.logging.log4j.Level.WARN);
356+
if (stack.right() instanceof AEItemKey itemKey)
357+
return parseItemStack(Pair.of(stack.left(), itemKey), service);
358+
if (stack.right() instanceof AEFluidKey fluidKey)
359+
return parseFluidStack(Pair.of(stack.left(), fluidKey), service);
360+
if (APAddon.APP_MEKANISTICS.isLoaded() && (stack.right() instanceof MekanismKey gasKey))
361+
return parseChemStack(Pair.of(stack.left(), gasKey), service);
362+
363+
AdvancedPeripherals.debug("Could not create table from unknown stack " + stack.right().getClass() + " - Report this to the maintainer of ap", org.apache.logging.log4j.Level.WARN);
364364
return null;
365365
}
366366

@@ -447,27 +447,27 @@ private static Map<String, Object> parseDISKDrive(DISKDrive drive, ItemStack sta
447447
}
448448

449449
private static Map<String, Object> parseItemStack(Pair<Long, AEItemKey> stack, @Nullable ICraftingService craftingService) {
450-
Map<String, Object> properties = LuaConverter.itemStackToLua(stack.getRight().getReadOnlyStack(), stack.getLeft());
451-
properties.put("isCraftable", craftingService != null && craftingService.isCraftable(stack.getRight()));
450+
Map<String, Object> properties = LuaConverter.itemStackToLua(stack.right().getReadOnlyStack(), stack.left());
451+
properties.put("isCraftable", craftingService != null && craftingService.isCraftable(stack.right()));
452452
return properties;
453453
}
454454

455455
private static Map<String, Object> parseFluidStack(Pair<Long, AEFluidKey> stack, @Nullable ICraftingService craftingService) {
456-
Map<String, Object> properties = LuaConverter.fluidStackToLua(stack.getRight().toStack(1), stack.getLeft());
457-
properties.put("isCraftable", craftingService != null && craftingService.isCraftable(stack.getRight()));
456+
Map<String, Object> properties = LuaConverter.fluidStackToLua(stack.right().toStack(1), stack.left());
457+
properties.put("isCraftable", craftingService != null && craftingService.isCraftable(stack.right()));
458458
return properties;
459459
}
460460

461461
private static Map<String, Object> parseChemStack(Pair<Long, MekanismKey> stack, @Nullable ICraftingService craftingService) {
462-
Map<String, Object> properties = LuaConverter.chemicalStackToLua(stack.getRight().withAmount(stack.getLeft()));
463-
properties.put("isCraftable", craftingService != null && craftingService.isCraftable(stack.getRight()));
462+
Map<String, Object> properties = LuaConverter.chemicalStackToLua(stack.right().withAmount(stack.left()));
463+
properties.put("isCraftable", craftingService != null && craftingService.isCraftable(stack.right()));
464464
return properties;
465465
}
466466

467467
public static Map<String, Object> parsePattern(Pair<EncodedPatternItem<?>, IPatternDetails> pattern) {
468468
Map<String, Object> properties = new HashMap<>();
469-
IPatternDetails patternDetails = pattern.getRight();
470-
String patternType = getPatternType(pattern.getLeft());
469+
IPatternDetails patternDetails = pattern.right();
470+
String patternType = getPatternType(pattern.left());
471471

472472
properties.put("inputs", Arrays.stream(patternDetails.getInputs()).map(AEApi::parsePatternInput).collect(Collectors.toList()));
473473
properties.put("outputs", patternDetails.getOutputs().stream().map(AEApi::parseGenericStack).collect(Collectors.toList()));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static MethodResult importToME(@NotNull IArguments arguments, IComputerAc
3434
Pair<ChemicalFilter, String> filter = ChemicalFilter.parse(new ObjectLuaTable(arguments.getTable(0)));
3535

3636
if (filter.rightPresent())
37-
return MethodResult.of(0, filter.getRight());
37+
return MethodResult.of(0, filter.right());
3838

3939
String side = arguments.getString(1);
4040
IChemicalHandler targetTank = ChemicalUtil.getHandlerFromDirection(side, peripheral.getPeripheralOwner());
@@ -48,7 +48,7 @@ public static MethodResult importToME(@NotNull IArguments arguments, IComputerAc
4848

4949
MEChemicalHandler chemicalHandler = new MEChemicalHandler(monitor, bridge);
5050

51-
return MethodResult.of(ChemicalUtil.moveChemical(targetTank, chemicalHandler, filter.getLeft()));
51+
return MethodResult.of(ChemicalUtil.moveChemical(targetTank, chemicalHandler, filter.left()));
5252
}
5353

5454
/**
@@ -65,7 +65,7 @@ public static MethodResult exportToTank(@NotNull IArguments arguments, IComputer
6565
Pair<ChemicalFilter, String> filter = ChemicalFilter.parse(new ObjectLuaTable(arguments.getTable(0)));
6666

6767
if (filter.rightPresent())
68-
return MethodResult.of(0, filter.getRight());
68+
return MethodResult.of(0, filter.right());
6969

7070
String side = arguments.getString(1);
7171
IChemicalHandler targetTank = ChemicalUtil.getHandlerFromDirection(side, peripheral.getPeripheralOwner());
@@ -79,7 +79,7 @@ public static MethodResult exportToTank(@NotNull IArguments arguments, IComputer
7979

8080
MEChemicalHandler chemicalHandler = new MEChemicalHandler(monitor, bridge);
8181

82-
return MethodResult.of(ChemicalUtil.moveChemical(chemicalHandler, targetTank, filter.getLeft()));
82+
return MethodResult.of(ChemicalUtil.moveChemical(chemicalHandler, targetTank, filter.left()));
8383
}
8484

8585
}

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/owner/OperationAbility.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation;
1212
import de.srendi.advancedperipherals.lib.peripherals.IPeripheralPlugin;
1313
import net.minecraft.core.component.PatchedDataComponentMap;
14-
import net.minecraft.world.item.component.CustomData;
1514
import org.jetbrains.annotations.NotNull;
1615
import org.jetbrains.annotations.Nullable;
1716

@@ -28,24 +27,24 @@ public OperationAbility(IPeripheralOwner owner) {
2827

2928
protected void setCooldown(@NotNull IPeripheralOperation<?> operation, int cooldown) {
3029
PatchedDataComponentMap patch = owner.getPatchedDataStorage();
31-
CustomData cooldowns = patch.getOrDefault(APDataComponents.ABILITY_COOLDOWNS.get(), CustomData.EMPTY);
30+
Map<String, Long> cooldowns = new HashMap<>(patch.getOrDefault(APDataComponents.ABILITY_COOLDOWNS.get(), Map.of()));
3231

3332
long newTS = System.currentTimeMillis() + cooldown;
34-
cooldowns = cooldowns.update(data -> data.putLong(operation.settingsName(), newTS));
33+
cooldowns.put(operation.settingsName(), newTS);
3534
patch.set(APDataComponents.ABILITY_COOLDOWNS.get(), cooldowns);
3635
owner.putDataStorage(patch.asPatch());
3736
}
3837

3938
protected int getCooldown(@NotNull IPeripheralOperation<?> operation) {
4039
PatchedDataComponentMap patch = owner.getPatchedDataStorage();
41-
CustomData cooldowns = patch.getOrDefault(APDataComponents.ABILITY_COOLDOWNS.get(), CustomData.EMPTY);
40+
Map<String, Long> cooldowns = patch.getOrDefault(APDataComponents.ABILITY_COOLDOWNS.get(), Map.of());
4241
String operationName = operation.settingsName();
43-
if (!cooldowns.contains(operationName)) {
42+
if (!cooldowns.containsKey(operationName)) {
4443
return 0;
4544
}
4645

4746
long currentTime = System.currentTimeMillis();
48-
return (int) Math.max(0, cooldowns.getUnsafe().getLong(operationName) - currentTime);
47+
return (int) Math.max(0, cooldowns.get(operationName) - currentTime);
4948
}
5049

5150
public void registerOperation(@NotNull IPeripheralOperation<?> operation) {
@@ -54,16 +53,17 @@ public void registerOperation(@NotNull IPeripheralOperation<?> operation) {
5453
return;
5554
}
5655
PatchedDataComponentMap patch = owner.getPatchedDataStorage();
57-
CustomData cooldowns = patch.getOrDefault(APDataComponents.ABILITY_COOLDOWNS.get(), CustomData.EMPTY);
58-
if (cooldowns.contains(operation.settingsName())) {
56+
Map<String, Long> cooldowns = patch.getOrDefault(APDataComponents.ABILITY_COOLDOWNS.get(), Map.of());
57+
if (cooldowns.containsKey(operation.settingsName())) {
5958
return;
6059
}
6160
int initialCooldown = operation.getInitialCooldown();
6261
if (initialCooldown < LibConfig.initialCooldownSensitivity) {
6362
return;
6463
}
6564
long newTS = System.currentTimeMillis() + initialCooldown;
66-
cooldowns = cooldowns.update(data -> data.putLong(operation.settingsName(), newTS));
65+
cooldowns = new HashMap<>(cooldowns);
66+
cooldowns.put(operation.settingsName(), newTS);
6767
patch.set(APDataComponents.ABILITY_COOLDOWNS.get(), cooldowns);
6868
owner.putDataStorage(patch.asPatch());
6969
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public final List<String> listDimensions() {
137137
@LuaFunction(mainThread = true)
138138
public final MethodResult getMoon() {
139139
Pair<Integer, String> moon = getCurrentMoonPhase();
140-
return MethodResult.of(moon.getLeft(), moon.getRight());
140+
return MethodResult.of(moon.left(), moon.right());
141141
}
142142

143143
private Pair<Integer, String> getCurrentMoonPhase() {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public final MethodResult getOwner() throws LuaException {
5454
public final MethodResult addItemToPlayer(String invDirection, Map<?, ?> item) throws LuaException {
5555
Pair<ItemFilter, String> filter = ItemFilter.parse(new ObjectLuaTable(item));
5656
if (filter.rightPresent()) {
57-
return MethodResult.of(null, filter.getRight());
57+
return MethodResult.of(null, filter.right());
5858
}
59-
return addItemCommon(invDirection, filter.getLeft());
59+
return addItemCommon(invDirection, filter.left());
6060
}
6161

6262
private MethodResult addItemCommon(String invDirection, ItemFilter filter) throws LuaException {
@@ -78,9 +78,9 @@ private MethodResult addItemCommon(String invDirection, ItemFilter filter) throw
7878
public final MethodResult removeItemFromPlayer(String invDirection, Map<?, ?> item) throws LuaException {
7979
Pair<ItemFilter, String> filter = ItemFilter.parse(new ObjectLuaTable(item));
8080
if (filter.rightPresent()) {
81-
return MethodResult.of(null, filter.getRight());
81+
return MethodResult.of(null, filter.right());
8282
}
83-
return removeItemCommon(invDirection, filter.getLeft());
83+
return removeItemCommon(invDirection, filter.left());
8484
}
8585

8686
private MethodResult removeItemCommon(String invDirection, ItemFilter filter) throws LuaException {

0 commit comments

Comments
 (0)