Configured portals

This commit is contained in:
Aleksey 2021-03-28 19:18:16 +03:00
parent 0a7391a35e
commit 068fa540be
4 changed files with 112 additions and 80 deletions

View file

@ -8,12 +8,17 @@ import com.google.gson.JsonObject;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import ru.betterend.BetterEnd;
import ru.betterend.config.ConfigWriter;
import ru.betterend.util.JsonFactory;
import ru.betterend.util.MHelper;
public class EndPortals {
public final static Identifier OVERWORLD_ID = World.OVERWORLD.getValue();
private static PortalInfo[] portals;
public static void loadPortals() {
@ -43,14 +48,21 @@ public class EndPortals {
return MHelper.max(portals.length - 1, 1);
}
public static ServerWorld getWorld(MinecraftServer server, int state) {
if (state >= portals.length) {
public static ServerWorld getWorld(MinecraftServer server, int portalId) {
if (portalId < 0 || portalId >= portals.length) {
return server.getOverworld();
}
return portals[state].getWorld(server);
return portals[portalId].getWorld(server);
}
public static Identifier getWorldId(int portalId) {
if (portalId < 0 || portalId >= portals.length) {
return OVERWORLD_ID;
}
return portals[portalId].dimension;
}
public static int getPortalState(Identifier item) {
public static int getPortalIdByItem(Identifier item) {
for (int i = 0; i < portals.length; i++) {
if (portals[i].item.equals(item)) {
return i;
@ -58,6 +70,14 @@ public class EndPortals {
}
return 0;
}
public static int getPortalIdByWorld(Identifier world) {
for (int i = 0; i < portals.length; i++) {
if (portals[i].dimension.equals(world)) {
return i;
}
}
return 0;
}
public static int getColor(int state) {
return portals[state].color;