diff --git a/src/main/java/com/vandendaelen/handles/blocks/tiles/TardisInterfaceTile.java b/src/main/java/com/vandendaelen/handles/blocks/tiles/TardisInterfaceTile.java index 3888aaf..02b87f2 100644 --- a/src/main/java/com/vandendaelen/handles/blocks/tiles/TardisInterfaceTile.java +++ b/src/main/java/com/vandendaelen/handles/blocks/tiles/TardisInterfaceTile.java @@ -2,6 +2,7 @@ import com.vandendaelen.handles.blocks.HandlesBlocks; import com.vandendaelen.handles.exceptions.NotATardisException; +import com.vandendaelen.handles.helpers.DimensionHelper; import com.vandendaelen.handles.misc.TardisInterfacePeripheral; import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheralTile; @@ -41,6 +42,27 @@ public Object[] getTardisLocation() throws NotATardisException { return new Object[]{pos.getX(), pos.getY(), pos.getZ()}; } + public Object[] getTardisDestination() throws NotATardisException{ + BlockPos pos = getTardis().getDestination(); + return new Object[]{pos.getX(), pos.getY(), pos.getZ()}; + } + + public Object[] setTardisDestination(int x, int y, int z) throws NotATardisException{ + ConsoleTile tardis = getTardis(); + tardis.setDestination(tardis.getDestinationDimension(), new BlockPos(x, y, z)); + return null; + } + + public Object[] setTardisDimensionDestination(int id) throws NotATardisException { + ConsoleTile tardis = getTardis(); + tardis.setDestination(DimensionHelper.getDimension(id), tardis.getDestination()); + return null; + } + + public Object[] getDimensions(){ + return DimensionHelper.getPrettyDimensionList().toArray(); + } + @Nullable @Override public IPeripheral getPeripheral(@Nonnull Direction direction) { diff --git a/src/main/java/com/vandendaelen/handles/helpers/DimensionHelper.java b/src/main/java/com/vandendaelen/handles/helpers/DimensionHelper.java new file mode 100644 index 0000000..9a0e2bc --- /dev/null +++ b/src/main/java/com/vandendaelen/handles/helpers/DimensionHelper.java @@ -0,0 +1,23 @@ +package com.vandendaelen.handles.helpers; + +import net.minecraft.world.dimension.DimensionType; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.fml.server.ServerLifecycleHooks; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.stream.Collectors; + +public class DimensionHelper { + public static DimensionType getDimension(int id){ + ArrayList worlds = new ArrayList<>(); + ServerLifecycleHooks.getCurrentServer().getWorlds().iterator().forEachRemaining(worlds::add); + return worlds.get(id).getDimension().getType(); + } + + public static ArrayList getPrettyDimensionList(){ + ArrayList worlds = new ArrayList<>(); + ServerLifecycleHooks.getCurrentServer().getWorlds().iterator().forEachRemaining(worlds::add); + return (ArrayList) worlds.stream().map(w -> MessageFormat.format("{0} - {1}", worlds.indexOf(w), w.getDimension().getType().getRegistryName().getNamespace())).collect(Collectors.toList()); + } +} diff --git a/src/main/java/com/vandendaelen/handles/misc/TardisInterfacePeripheral.java b/src/main/java/com/vandendaelen/handles/misc/TardisInterfacePeripheral.java index 589d5b8..87f2239 100644 --- a/src/main/java/com/vandendaelen/handles/misc/TardisInterfacePeripheral.java +++ b/src/main/java/com/vandendaelen/handles/misc/TardisInterfacePeripheral.java @@ -28,7 +28,11 @@ public String getType() { @Override public String[] getMethodNames() { return new String[]{ - "getLocation" + "getLocation", + "getDestination", + "setDestination", + "setDimension", + "getDimensions" }; } @@ -39,6 +43,14 @@ public Object[] callMethod(@Nonnull IComputerAccess iComputerAccess, @Nonnull IL switch (method){ case 0://getLocation return tile.getTardisLocation(); + case 1://getDestination + return tile.getTardisDestination(); + case 2://setDestination + return tile.setTardisDestination((int)objects[0], (int)objects[1], (int)objects[2]); + case 3: + return tile.setTardisDimensionDestination((int)objects[0]); + case 4: + return tile.getDimensions(); default: return null; }