Skip to content

Commit

Permalink
started on functions
Browse files Browse the repository at this point in the history
  • Loading branch information
LotuxPunk committed Apr 19, 2020
1 parent d842e04 commit b2f1bc0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ServerWorld> worlds = new ArrayList<>();
ServerLifecycleHooks.getCurrentServer().getWorlds().iterator().forEachRemaining(worlds::add);
return worlds.get(id).getDimension().getType();
}

public static ArrayList<String> getPrettyDimensionList(){
ArrayList<ServerWorld> worlds = new ArrayList<>();
ServerLifecycleHooks.getCurrentServer().getWorlds().iterator().forEachRemaining(worlds::add);
return (ArrayList<String>) worlds.stream().map(w -> MessageFormat.format("{0} - {1}", worlds.indexOf(w), w.getDimension().getType().getRegistryName().getNamespace())).collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public String getType() {
@Override
public String[] getMethodNames() {
return new String[]{
"getLocation"
"getLocation",
"getDestination",
"setDestination",
"setDimension",
"getDimensions"
};
}

Expand All @@ -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;
}
Expand Down

0 comments on commit b2f1bc0

Please sign in to comment.