Skip to content

Commit 6c4fc17

Browse files
committed
[#777] Fixed IArguments has been closed being thrown with some functions that still use the wrong table functions
1 parent 0319cda commit 6c4fc17

6 files changed

Lines changed: 24 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
9+
10+
### Added
11+
- [#755] Added disabled peripherals, a better way to check if a peripheral is disabled in the config. See [docs](https://docs.advanced-peripherals.de/latest/guides/disabled_peripherals)
12+
13+
### Fixed
14+
- [#784] Fixed that the energy detector transfer rate limit is not enforced
15+
- [#772] Fixed that the inventory manager does not save it's content
916
## [1.20.1-0.7.45r] - 2025-08-02
1017

1118
### Fixed

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.jetbrains.annotations.NotNull;
4242
import org.jetbrains.annotations.Nullable;
4343

44-
import java.util.Optional;
4544
import java.util.stream.Stream;
4645

4746
import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.DIG;
@@ -61,10 +60,7 @@ public AutomataBlockHandPlugin(AutomataCorePeripheral automataCore) {
6160

6261
@LuaFunction(mainThread = true)
6362
public final MethodResult digBlock(@NotNull IArguments arguments) throws LuaException {
64-
Optional<LuaTable<?, ?>> optOptions = arguments.optTableUnsafe(0);
65-
LuaTable<?, ?> options = EmptyLuaTable.INSTANCE;
66-
if (optOptions.isPresent())
67-
options = optOptions.get();
63+
LuaTable<?, ?> options = EmptyLuaTable.orEmpty(arguments.optTable(0).orElse(null));
6864

6965
boolean sneak = options.optBoolean("sneak").orElse(false);
7066
float yaw = options.optDouble("yaw").orElse(0d).floatValue();
@@ -87,10 +83,7 @@ public final MethodResult digBlock(@NotNull IArguments arguments) throws LuaExce
8783

8884
@LuaFunction(mainThread = true)
8985
public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaException {
90-
Optional<LuaTable<?, ?>> optOptions = arguments.optTableUnsafe(0);
91-
LuaTable<?, ?> options = EmptyLuaTable.INSTANCE;
92-
if (optOptions.isPresent())
93-
options = optOptions.get();
86+
LuaTable<?, ?> options = EmptyLuaTable.orEmpty(arguments.optTable(0).orElse(null));
9487

9588
boolean sneak = options.optBoolean("sneak").orElse(false);
9689
float yaw = options.optDouble("yaw").orElse(0d).floatValue();
@@ -124,8 +117,7 @@ public final MethodResult useOnBlock(@NotNull IArguments arguments) throws LuaEx
124117
*/
125118
@LuaFunction(mainThread = true)
126119
public MethodResult placeBlock(@NotNull IArguments arguments) throws LuaException {
127-
Optional<LuaTable<?, ?>> optOptions = arguments.optTableUnsafe(0);
128-
final LuaTable<?, ?> options = optOptions.orElse(EmptyLuaTable.INSTANCE);
120+
LuaTable<?, ?> options = EmptyLuaTable.orEmpty(arguments.optTable(0).orElse(null));
129121

130122
ITurtleAccess turtle = automataCore.getPeripheralOwner().getTurtle();
131123
CompassPeripheral compassPeripheral = Stream.of(TurtleSide.values()).map(side -> turtle.getPeripheral(side) instanceof CompassPeripheral compass ? compass : null).filter(peripheral -> peripheral != null).findFirst().orElse(null);

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.jetbrains.annotations.Nullable;
2525
import java.util.List;
2626
import java.util.Map;
27-
import java.util.Optional;
2827
import java.util.function.Predicate;
2928

3029
import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.USE_ON_ANIMAL;
@@ -45,10 +44,7 @@ public AutomataEntityHandPlugin(AutomataCorePeripheral automataCore, Predicate<E
4544

4645
@LuaFunction(mainThread = true)
4746
public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaException {
48-
Optional<LuaTable<?, ?>> optOptions = arguments.optTableUnsafe(0);
49-
LuaTable<?, ?> options = EmptyLuaTable.INSTANCE;
50-
if (optOptions.isPresent())
51-
options = optOptions.get();
47+
LuaTable<?, ?> options = EmptyLuaTable.orEmpty(arguments.optTable(0).orElse(null));
5248

5349
boolean sneak = options.optBoolean("sneak").orElse(false);
5450
float yaw = options.optDouble("yaw").orElse(0d).floatValue();
@@ -68,10 +64,7 @@ public final MethodResult useOnAnimal(@NotNull IArguments arguments) throws LuaE
6864

6965
@LuaFunction(mainThread = true)
7066
public final MethodResult inspectAnimal(@NotNull IArguments arguments) throws LuaException {
71-
Optional<LuaTable<?, ?>> optOptions = arguments.optTableUnsafe(0);
72-
LuaTable<?, ?> options = EmptyLuaTable.INSTANCE;
73-
if (optOptions.isPresent())
74-
options = optOptions.get();
67+
LuaTable<?, ?> options = EmptyLuaTable.orEmpty(arguments.optTable(0).orElse(null));
7568

7669
float yaw = options.optDouble("yaw").orElse(0d).floatValue();
7770
float pitch = options.optDouble( "pitch").orElse(0d).floatValue();

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
import org.jetbrains.annotations.NotNull;
2424
import org.jetbrains.annotations.Nullable;
25-
import java.util.Optional;
2625
import java.util.function.Predicate;
2726

2827
import static de.srendi.advancedperipherals.common.addons.computercraft.operations.SingleOperation.CAPTURE_ANIMAL;
@@ -76,10 +75,7 @@ protected Entity extractEntity() {
7675

7776
@LuaFunction(mainThread = true)
7877
public final MethodResult captureAnimal(@NotNull IArguments arguments) throws LuaException {
79-
Optional<LuaTable<?, ?>> optOptions = arguments.optTableUnsafe(0);
80-
LuaTable<?, ?> options = EmptyLuaTable.INSTANCE;
81-
if (optOptions.isPresent())
82-
options = optOptions.get();
78+
LuaTable<?, ?> options = EmptyLuaTable.orEmpty(arguments.optTable(0).orElse(null));
8379

8480
float yaw = options.optDouble("yaw").orElse(0d).floatValue();
8581
float pitch = options.optDouble( "pitch").orElse(0d).floatValue();

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.jetbrains.annotations.NotNull;
2121
import java.util.HashMap;
2222
import java.util.Map;
23-
import java.util.Optional;
2423

2524
public class AutomataLookPlugin extends AutomataCorePlugin {
2625

@@ -30,10 +29,7 @@ public AutomataLookPlugin(AutomataCorePeripheral automataCore) {
3029

3130
@LuaFunction(mainThread = true)
3231
public final MethodResult lookAtBlock(@NotNull IArguments arguments) throws LuaException {
33-
Optional<LuaTable<?, ?>> optOptions = arguments.optTableUnsafe(0);
34-
LuaTable<?, ?> options = EmptyLuaTable.INSTANCE;
35-
if (optOptions.isPresent())
36-
options = optOptions.get();
32+
LuaTable<?, ?> options = EmptyLuaTable.orEmpty(arguments.optTable(0).orElse(null));
3733

3834
float yaw = options.optDouble("yaw").orElse(0d).floatValue();
3935
float pitch = options.optDouble( "pitch").orElse(0d).floatValue();
@@ -56,10 +52,7 @@ public final MethodResult lookAtBlock(@NotNull IArguments arguments) throws LuaE
5652

5753
@LuaFunction(mainThread = true)
5854
public final MethodResult lookAtEntity(@NotNull IArguments arguments) throws LuaException {
59-
Optional<LuaTable<?, ?>> optOptions = arguments.optTableUnsafe(0);
60-
LuaTable<?, ?> options = EmptyLuaTable.INSTANCE;
61-
if (optOptions.isPresent())
62-
options = optOptions.get();
55+
LuaTable<?, ?> options = EmptyLuaTable.orEmpty(arguments.optTable(0).orElse(null));
6356

6457
float yaw = options.optDouble("yaw").orElse(0d).floatValue();
6558
float pitch = options.optDouble( "pitch").orElse(0d).floatValue();

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package de.srendi.advancedperipherals.common.util;
22

33
import dan200.computercraft.api.lua.LuaTable;
4+
import dan200.computercraft.api.lua.ObjectLuaTable;
45
import org.jetbrains.annotations.NotNull;
56
import org.jetbrains.annotations.Nullable;
67

78
import java.util.Collection;
89
import java.util.List;
10+
import java.util.Map;
911
import java.util.Set;
1012

1113
public class EmptyLuaTable implements LuaTable<Object, Object> {
@@ -55,4 +57,11 @@ public Collection<Object> values() {
5557
public Set<Entry<Object, Object>> entrySet() {
5658
return Set.of();
5759
}
60+
61+
public static LuaTable<Object, Object> orEmpty(@Nullable Map<?, ?> table) {
62+
if (table == null)
63+
return INSTANCE;
64+
return new ObjectLuaTable(table);
65+
}
66+
5867
}

0 commit comments

Comments
 (0)