Repository: sirendii/advancedperipherals
Issue: cardinal directions aren't working, contrary to the docs.

### Describe

Mods: ONLY CC:Tweaked and Advanced Peripherals.

The inventory manager does not currently allow cardinal directions. (even though supposedly it should? according to the docs at least)

Please fix.


example script:
`manager = peripheral.find("inventoryManager")
manager.addItemToPlayer("UP", 50, -1)`


Do correct me if I am doing something wrong here, but yeah it appears to not work.
This also means that the example script on the docs won't work. 
ALSO unrelated but the docs have the NBT version of the example in the non-nbt area and the non-nbt version in the nbt area.

### Steps to reproduce

1. get your CC setup. (put an inventory manager and such.)
2. Put a chest on top of the inventory manager,
3. put something in it
4. call `manager.addItemToPlayer("UP", 4, -1)`
5. It won't work because apparently the cardinal directions aren't enabled contrary to the docs.

### Multiplayer?

No

### Version

1.19.2-0.7.27r (Latest 1.19.2)

### Minecraft, Forge and maybe other related mods versions

Forge 43.2.8, Minecraft 1.19.2

### Screenshots or Videos

_No response_

### Crashlog/log

_No response_

Changed files:
src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java, src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java

diff --git a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java
index 7b75ab26..a11c27a0 100644
--- a/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java
+++ b/src/main/java/de/srendi/advancedperipherals/common/util/CoordUtil.java
@@ -12,7 +12,7 @@ import net.minecraft.world.level.Level;
 import net.minecraft.world.phys.AABB;
 import org.jetbrains.annotations.NotNull;
 
-import java.util.Objects;
+import java.util.Locale;
 
 public class CoordUtil {
 
@@ -49,32 +49,43 @@ public class CoordUtil {
     }
 
     public static Direction getDirection(FrontAndTop orientation, String computerSide) throws LuaException {
-        if (Direction.byName(computerSide) != null) return Direction.byName(computerSide);
+        if (computerSide == null) {
+            throw new LuaException("null is not a valid side");
+        }
+
+        computerSide = computerSide.toLowerCase(Locale.ROOT);
+        Direction dir = Direction.byName(computerSide);
+        if (dir != null)
+            return dir;
         Direction top = orientation.top();
         Direction front = orientation.front();
 
+        final ComputerSide side = ComputerSide.valueOfInsensitive(computerSide);
+        if (side == null) {
+            throw new LuaException(computerSide + " is not a valid side");
+        }
+
         if (front.getAxis() == Direction.Axis.Y) {
-            if (front == Direction.UP) {
-                if (Objects.equals(computerSide, ComputerSide.FRONT.toString())) return Direction.UP;
-                if (Objects.equals(computerSide, ComputerSide.BACK.toString())) return Direction.DOWN;
+            switch (side) {
+                case FRONT: return front;
+                case BACK: return front.getOpposite();
+                case TOP: return top;
+                case BOTTOM: return top.getOpposite();
+                case RIGHT: return top.getClockWise();
+                case LEFT: return top.getCounterClockWise();
             }
-            if (front == Direction.DOWN) {
-                if (Objects.equals(computerSide, ComputerSide.FRONT.toString())) return Direction.DOWN;
-                if (Objects.equals(computerSide, ComputerSide.BACK.toString())) return Direction.UP;
+        } else {
+            switch (side) {
+                case FRONT: return front;
+                case BACK: return front.getOpposite();
+                case TOP: return Direction.UP;
+                case BOTTOM: return Direction.DOWN;
+                case RIGHT: return front.getCounterClockWise();
+                case LEFT: return front.getClockWise();
             }
-            if (Objects.equals(computerSide, ComputerSide.TOP.toString())) return top;
-            if (Objects.equals(computerSide, ComputerSide.BOTTOM.toString())) return top.getOpposite();
-            if (Objects.equals(computerSide, ComputerSide.RIGHT.toString())) return top.getClockWise();
-            if (Objects.equals(computerSide, ComputerSide.LEFT.toString())) return top.getCounterClockWise();
         }
-        if (Objects.equals(computerSide, ComputerSide.FRONT.toString())) return front;
-        if (Objects.equals(computerSide, ComputerSide.BACK.toString())) return front.getOpposite();
-        if (Objects.equals(computerSide, ComputerSide.TOP.toString())) return Direction.UP;
-        if (Objects.equals(computerSide, ComputerSide.BOTTOM.toString())) return Direction.DOWN;
-        if (Objects.equals(computerSide, ComputerSide.RIGHT.toString())) return front.getCounterClockWise();
-        if (Objects.equals(computerSide, ComputerSide.LEFT.toString())) return front.getClockWise();
 
-        throw new LuaException(computerSide + " is not a valid side");
+        throw new LuaException(computerSide + " is not a expected side");
     }
 
 }
diff --git a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java
index 81261a0b..73618696 100644
--- a/src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java
+++ b/src/main/java/de/srendi/advancedperipherals/lib/peripherals/BasePeripheral.java
@@ -22,7 +22,6 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.function.BiConsumer;
 import java.util.function.Consumer;
@@ -132,9 +131,7 @@ public abstract class BasePeripheral<O extends IPeripheralOwner> implements IBas
     }
 
     protected Direction validateSide(String direction) throws LuaException {
-        String dir = direction.toUpperCase(Locale.ROOT);
-
-        return CoordUtil.getDirection(owner.getOrientation(), dir);
+        return CoordUtil.getDirection(owner.getOrientation(), direction);
     }
 
     @Override