Skip to content

Commit d8f030a

Browse files
committed
some clarity for lua converter
1 parent dc8aad5 commit d8f030a

12 files changed

Lines changed: 76 additions & 58 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod_id=advancedperipherals
77
# do not include mod_version/minecraft_version with equals sign anywhere else in the file (even in comments)
88
# also do not add space around the equal sign
99
# since we are using poor grep command to do automation :p
10-
mod_version=0.7.58b
10+
mod_version=0.8.0
1111
minecraft_version=1.21.1
1212
mod_artifact_suffix=
1313
neo_version=21.1.220

src/main/java/de/srendi/advancedperipherals/common/addons/APAddon.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public enum APAddon {
88

99
AE2("ae2"),
10-
AE2_THINGS("ae2things"),
10+
AE2THINGS("ae2things"),
1111
APP_MEKANISTICS("appmek"),
1212
CURIOS("curios"),
1313
MEKANISM("mekanism"),

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ public static Map<String, Object> parseCraftingCPU(ICraftingCPU cpu, boolean rec
517517
public static Object parseCraftingJob(CraftingJobStatus status, @Nullable AECraftJob craftJob, @Nullable ICraftingCPU cpu) {
518518
Map<String, Object> properties = new HashMap<>();
519519

520-
properties.put("bridge_id", craftJob == null ? -1 : craftJob.getId());
520+
properties.put("bridgeId", craftJob == null ? -1 : craftJob.getId());
521521
properties.put("quantity", status.crafting().amount());
522522
properties.put("resource", parseGenericStack(status.crafting()));
523523

@@ -710,7 +710,7 @@ public static long getTotalItemStorage(IGridNode node) {
710710
if (cell.getKeyType().getClass().isAssignableFrom(AEKeyType.items().getClass())) {
711711
total += cell.getBytes(null);
712712
}
713-
} else if (APAddon.AE2_THINGS.isLoaded() && stack.getItem() instanceof DISKDrive disk) {
713+
} else if (APAddon.AE2THINGS.isLoaded() && stack.getItem() instanceof DISKDrive disk) {
714714
if (disk.getKeyType().toString().equals("ae2:i")) {
715715
total += disk.getBytes(null);
716716
}
@@ -798,7 +798,7 @@ public static long getUsedItemStorage(IGridNode node) {
798798

799799
used += cellInventory.getUsedBytes();
800800
}
801-
} else if (APAddon.AE2_THINGS.isLoaded() && stack.getItem() instanceof DISKDrive) {
801+
} else if (APAddon.AE2THINGS.isLoaded() && stack.getItem() instanceof DISKDrive) {
802802
DISKCellInventory diskCellInventory = DISKCellHandler.INSTANCE.getCellInventory(stack, null);
803803
if (diskCellInventory != null) {
804804
used += diskCellInventory.getNbtItemCount();
@@ -959,7 +959,7 @@ public static List<Object> listCells(IGridNode node) {
959959

960960
if (stack.getItem() instanceof IBasicCellItem cell) {
961961
items.add(parseCell(cell, stack));
962-
} else if (APAddon.AE2_THINGS.isLoaded() && stack.getItem() instanceof DISKDrive disk) {
962+
} else if (APAddon.AE2THINGS.isLoaded() && stack.getItem() instanceof DISKDrive disk) {
963963
items.add(parseDISKDrive(disk, stack));
964964
}
965965
}

src/main/java/de/srendi/advancedperipherals/common/addons/computercraft/operations/SimpleFreeOperation.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package de.srendi.advancedperipherals.common.addons.computercraft.operations;
22

3+
import dan200.computercraft.api.lua.IArguments;
4+
import dan200.computercraft.api.lua.LuaException;
5+
import dan200.computercraft.api.lua.MethodResult;
36
import de.srendi.advancedperipherals.lib.peripherals.IPeripheralOperation;
47
import net.neoforged.neoforge.common.ModConfigSpec;
58

69
import java.util.HashMap;
710
import java.util.Map;
811

9-
import dan200.computercraft.api.lua.IArguments;
10-
import dan200.computercraft.api.lua.LuaException;
11-
import dan200.computercraft.api.lua.MethodResult;
12-
1312
public enum SimpleFreeOperation implements IPeripheralOperation<Void> {
1413
CHAT_MESSAGE(1000),
1514
SADDLE_CAPTURE(5000);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public boolean isOnCooldown(IPeripheralOperation<?> operation) {
134134
public void collectConfiguration(Map<String, Object> data) {
135135
for (IPeripheralOperation<?> operation : allowedOperations.values()) {
136136
Map<String, Object> operData = operation.computerDescription();
137-
data.put("getCost", (ILuaFunction) operation::getCostLua);
137+
operData.put("getCost", (ILuaFunction) operation::getCostLua);
138138
data.put(operation.settingsName(), operData);
139139
}
140140
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,13 @@ public final MethodResult scanEntities(@NotNull IArguments arguments) throws Lua
180180
return withOperation(SCAN_ENTITIES, new SphereOperationContext(radius), context -> {
181181
return context.getRadius() > SCAN_ENTITIES.getMaxCostRadius() ? MethodResult.of(null, "Radius exceeds max value") : null;
182182
}, context -> {
183-
Vec3 pos = this.getPhysicsPos();
183+
IPeripheralOwner owner = this.getPeripheralOwner();
184+
Vec3 pos = owner.getPhysicsPos();
184185
AABB box = new AABB(pos, pos).inflate(context.getRadius() + 0.5);
185186
LuaConverter.EntityConverter.Context convContext = LuaConverter.entityContextBuilder()
186187
.detailed(detailed)
187188
.position(pos)
189+
.orientation(owner.getOrientation())
188190
.build();
189191
List<Map<String, Object>> entities = getLevel()
190192
.getEntities((Entity) null, box, entity -> entity instanceof LivingEntity && entity.isAlive())

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import net.minecraft.world.phys.Vec3;
2222

2323
import org.jetbrains.annotations.NotNull;
24-
import org.jetbrains.annotations.Nullable;
2524

2625
import java.util.List;
2726
import java.util.Map;
@@ -39,7 +38,7 @@ public AutomataEntityHandPlugin(AutomataCorePeripheral automataCore, Predicate<E
3938
}
4039

4140
@Override
42-
public @Nullable IPeripheralOperation<?>[] getOperations() {
41+
public IPeripheralOperation<?> @NotNull [] getOperations() {
4342
return new IPeripheralOperation[]{USE_ON_ANIMAL};
4443
}
4544

@@ -96,6 +95,7 @@ public final MethodResult searchAnimals(IArguments args) throws LuaException {
9695
.detailed(detailed)
9796
.itemInHand(owner.getToolInMainHand())
9897
.position(currentPos)
98+
.orientation(owner.getOrientation())
9999
.build();
100100
List<Map<String, Object>> entities = owner
101101
.getLevel()

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,23 @@ public final MethodResult lookAtEntity(@NotNull IArguments arguments) throws Lua
7171
float pitch = options.optDouble("pitch").orElse(0d).floatValue();
7272

7373
automataCore.addRotationCycle();
74-
HitResult result = automataCore.getPeripheralOwner().withPlayer(APFakePlayer.wrapActionWithRot(yaw, pitch, p -> p.findHit(false, true)));
74+
TurtlePeripheralOwner owner = automataCore.getPeripheralOwner();
75+
HitResult result = owner.withPlayer(APFakePlayer.wrapActionWithRot(yaw, pitch, p -> p.findHit(false, true)));
7576
if (result.getType() == HitResult.Type.MISS) {
7677
return MethodResult.of(null, "No entity find");
7778
}
7879

7980
EntityHitResult entityHit = (EntityHitResult) result;
80-
Vec3 origin = automataCore.getPhysicsPos();
81-
return MethodResult.of(LuaConverter.entityToLua(entityHit.getEntity(), LuaConverter.entityContextBuilder().detailed().position(origin).build()));
81+
return MethodResult.of(
82+
LuaConverter.entityToLua(
83+
entityHit.getEntity(),
84+
LuaConverter.entityContextBuilder()
85+
.detailed()
86+
.position(owner.getPhysicsPos())
87+
.orientation(owner.getOrientation())
88+
.build()
89+
)
90+
);
8291
}
8392

8493
}

src/main/java/de/srendi/advancedperipherals/common/addons/refinedstorage/RSApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ public static Object parseDiskDrive(StorageNetworkNode diskDrive, InWorldNetwork
657657
properties.put("total", diskDrive.getCapacity());
658658
properties.put("disks", disks);
659659
properties.put("mode", storageConfiguration.getFilterMode().toString());
660-
properties.put("access_type", storageConfiguration.getAccessMode().toString());
660+
properties.put("accessType", storageConfiguration.getAccessMode().toString());
661661
properties.put("position", LuaConverter.posToLua(nodeContainer.getLocalPosition()));
662662
properties.put("priority", nodeContainer.getPriority());
663663

@@ -690,7 +690,7 @@ public static Object parseStorageDisk(StateTrackedStorage disk) {
690690
public static Object parseCraftingTask(@Nullable RSCraftJob task, TaskStatus status, @Nullable AutocraftingNetworkComponent autocraftingComponent) {
691691
Map<String, Object> properties = new HashMap<>();
692692

693-
properties.put("bridge_id", task == null ? -1 : task.getId());
693+
properties.put("bridgeId", task == null ? -1 : task.getId());
694694
properties.put("id", status.info().id().toString());
695695
properties.put("quantity", status.info().amount());
696696
// The "stored" attribute of the Item does not always work. I guess this is a bug, I at least reported it.

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,19 @@ public static ComputerSide getComputerSide(FrontAndTop orientation, Direction di
186186
* put "x", "y", "z", and/or "f", "r", "u" coords based on configuration
187187
* @see putFRUCoords
188188
*/
189-
public static void putRelativeCoords(Map<? super String, ? super Double> data, double x, double y, double z, Matrix3dc orientation) {
189+
public static void putRelativeCoords(Map<? super String, ? super Double> data, double x, double y, double z, @Nullable Matrix3dc orientation) {
190190
data.put("x", x);
191191
data.put("y", y);
192192
data.put("z", z);
193-
putFRUCoords(data, x, y, z, orientation);
193+
if (orientation != null) {
194+
putFRUCoords(data, x, y, z, orientation);
195+
}
194196
}
195197

196198
/**
197199
* put "f", "r", "u" coords into the map
198200
*/
199-
public static void putFRUCoords(Map<? super String, ? super Double> data, double x, double y, double z, Matrix3dc orientation) {
201+
public static void putFRUCoords(Map<? super String, ? super Double> data, double x, double y, double z, @NotNull Matrix3dc orientation) {
200202
Vector3d rpos = orientation.transformTranspose(new Vector3d(x, y, z));
201203
data.put("r", rpos.x);
202204
data.put("u", rpos.y);

0 commit comments

Comments
 (0)