fix config
This commit is contained in:
		
							parent
							
								
									0d1e607206
								
							
						
					
					
						commit
						a654eec852
					
				@ -10,7 +10,7 @@ yarn_mappings=1.21+build.2
 | 
				
			|||||||
loader_version=0.15.11
 | 
					loader_version=0.15.11
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Mod Properties
 | 
					# Mod Properties
 | 
				
			||||||
mod_version=0.9.4
 | 
					mod_version=0.9.5
 | 
				
			||||||
maven_group=quimufu.colourful-portalRepresentations
 | 
					maven_group=quimufu.colourful-portalRepresentations
 | 
				
			||||||
archives_base_name=colourful-portalRepresentations
 | 
					archives_base_name=colourful-portalRepresentations
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1,5 +1,6 @@
 | 
				
			|||||||
package quimufu.colourful_portals;
 | 
					package quimufu.colourful_portals;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import eu.midnightdust.lib.config.MidnightConfig;
 | 
				
			||||||
import net.fabricmc.api.ModInitializer;
 | 
					import net.fabricmc.api.ModInitializer;
 | 
				
			||||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
 | 
					import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
 | 
				
			||||||
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
 | 
					import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
 | 
				
			||||||
@ -63,6 +64,7 @@ public class ColourfulPortalsMod implements ModInitializer {
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onInitialize() {
 | 
					    public void onInitialize() {
 | 
				
			||||||
        LOGGER.info("Colouring Portals...");
 | 
					        LOGGER.info("Colouring Portals...");
 | 
				
			||||||
 | 
					        MidnightConfig.init(MOD_ID, ColourfulPortalConfig.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (String id : ColourfulPortalConfig.getAllPortalBlocks()) {
 | 
					        for (String id : ColourfulPortalConfig.getAllPortalBlocks()) {
 | 
				
			||||||
            LOGGER.info(id);
 | 
					            LOGGER.info(id);
 | 
				
			||||||
@ -125,6 +127,7 @@ public class ColourfulPortalsMod implements ModInitializer {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        PORTAL_MANAGER = new PortalManager(currentLinkingSystem, portalCandidateList, portalList);
 | 
					        PORTAL_MANAGER = new PortalManager(currentLinkingSystem, portalCandidateList, portalList);
 | 
				
			||||||
 | 
					        PORTAL_MANAGER.onLoad(minecraftServer);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private PortalLinkingSystem getCurrentlyConfiguredLinkingSystem(MinecraftServer minecraftServer) {
 | 
					    private PortalLinkingSystem getCurrentlyConfiguredLinkingSystem(MinecraftServer minecraftServer) {
 | 
				
			||||||
 | 
				
			|||||||
@ -10,12 +10,12 @@ import java.util.Set;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
public class ColourfulPortalConfig extends MidnightConfig {
 | 
					public class ColourfulPortalConfig extends MidnightConfig {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Comment(category = "text")
 | 
					 | 
				
			||||||
    public static Comment explanation;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Entry(category = "text", name = "Disable Immersive Portals integration")
 | 
					    @Entry(category = "text", name = "Disable Immersive Portals integration")
 | 
				
			||||||
    public static boolean disableImmersivePortals = false;
 | 
					    public static boolean disableImmersivePortals = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Comment(category = "text")
 | 
				
			||||||
 | 
					    public static Comment explanation;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Entry(category = "text", name = "Blocks that create white portals")
 | 
					    @Entry(category = "text", name = "Blocks that create white portals")
 | 
				
			||||||
    public static List<String> white = Lists.newArrayList("minecraft:white_wool");
 | 
					    public static List<String> white = Lists.newArrayList("minecraft:white_wool");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -64,7 +64,8 @@ public class ColourfulPortalConfig extends MidnightConfig {
 | 
				
			|||||||
    @Entry(category = "text", name = "Blocks that create black portals")
 | 
					    @Entry(category = "text", name = "Blocks that create black portals")
 | 
				
			||||||
    public static List<String> black = Lists.newArrayList("minecraft:black_wool");
 | 
					    public static List<String> black = Lists.newArrayList("minecraft:black_wool");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Entry(category = "text", name = "Blocks that create fully transparent portals")
 | 
					    //todo: disabled until i find a good solution
 | 
				
			||||||
 | 
					    //@Entry(category = "text", name = "Blocks that create fully transparent portals")
 | 
				
			||||||
    public static List<String> none = Lists.newArrayList();
 | 
					    public static List<String> none = Lists.newArrayList();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static Set<String> getAllPortalBlocks() {
 | 
					    public static Set<String> getAllPortalBlocks() {
 | 
				
			||||||
 | 
				
			|||||||
@ -1,8 +1,6 @@
 | 
				
			|||||||
package quimufu.colourful_portals.portal;
 | 
					package quimufu.colourful_portals.portal;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import net.minecraft.entity.Entity;
 | 
					import net.minecraft.entity.Entity;
 | 
				
			||||||
import net.minecraft.registry.RegistryKey;
 | 
					 | 
				
			||||||
import net.minecraft.registry.RegistryKeys;
 | 
					 | 
				
			||||||
import net.minecraft.server.MinecraftServer;
 | 
					import net.minecraft.server.MinecraftServer;
 | 
				
			||||||
import net.minecraft.server.world.ServerWorld;
 | 
					import net.minecraft.server.world.ServerWorld;
 | 
				
			||||||
import net.minecraft.util.Identifier;
 | 
					import net.minecraft.util.Identifier;
 | 
				
			||||||
@ -20,7 +18,7 @@ import static quimufu.colourful_portals.ColourfulPortalsMod.LOGGER;
 | 
				
			|||||||
import static quimufu.colourful_portals.ColourfulPortalsMod.MOD_ID;
 | 
					import static quimufu.colourful_portals.ColourfulPortalsMod.MOD_ID;
 | 
				
			||||||
import static quimufu.colourful_portals.portal.PortalHelper.getAxisW;
 | 
					import static quimufu.colourful_portals.portal.PortalHelper.getAxisW;
 | 
				
			||||||
import static quimufu.colourful_portals.portal.PortalHelper.insideOf;
 | 
					import static quimufu.colourful_portals.portal.PortalHelper.insideOf;
 | 
				
			||||||
import static quimufu.colourful_portals.portal.PortalManager.getDimId;
 | 
					import static quimufu.colourful_portals.portal.PortalHelper.getDimId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class DefaultLinkingSystem implements PortalLinkingSystem {
 | 
					public class DefaultLinkingSystem implements PortalLinkingSystem {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -45,7 +43,7 @@ public class DefaultLinkingSystem implements PortalLinkingSystem {
 | 
				
			|||||||
            PortalRepresentation portalRepresentation = node.getValue();
 | 
					            PortalRepresentation portalRepresentation = node.getValue();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            Node<PortalRepresentation> finalNode = node;
 | 
					            Node<PortalRepresentation> finalNode = node;
 | 
				
			||||||
            insideOf(portalRepresentation.location())
 | 
					            insideOf(portalRepresentation)
 | 
				
			||||||
                    .forEachRemaining(blockPos -> {
 | 
					                    .forEachRemaining(blockPos -> {
 | 
				
			||||||
                        Set<Node<PortalRepresentation>> portalsAtPosition = positionalLookup.computeIfAbsent(blockPos, (k) -> new HashSet<>(1));
 | 
					                        Set<Node<PortalRepresentation>> portalsAtPosition = positionalLookup.computeIfAbsent(blockPos, (k) -> new HashSet<>(1));
 | 
				
			||||||
                        portalsAtPosition.add(finalNode);
 | 
					                        portalsAtPosition.add(finalNode);
 | 
				
			||||||
@ -65,7 +63,7 @@ public class DefaultLinkingSystem implements PortalLinkingSystem {
 | 
				
			|||||||
        Optional<Node<PortalRepresentation>> portalOpt = portalRepresentationCandidated.stream()
 | 
					        Optional<Node<PortalRepresentation>> portalOpt = portalRepresentationCandidated.stream()
 | 
				
			||||||
                .filter(n -> !n.orphaned())
 | 
					                .filter(n -> !n.orphaned())
 | 
				
			||||||
                .filter(n -> n.getValue() != null)
 | 
					                .filter(n -> n.getValue() != null)
 | 
				
			||||||
                .filter(n -> getAxisW(n.getValue().location()).rotateYClockwise().getAxis() == a)
 | 
					                .filter(n -> getAxisW(n.getValue()).rotateYClockwise().getAxis() == a)
 | 
				
			||||||
                .filter(n -> Objects.equals(n.getValue().dimensionId(), getDimId(world)))
 | 
					                .filter(n -> Objects.equals(n.getValue().dimensionId(), getDimId(world)))
 | 
				
			||||||
                .findAny();
 | 
					                .findAny();
 | 
				
			||||||
        if (portalOpt.isPresent()) {
 | 
					        if (portalOpt.isPresent()) {
 | 
				
			||||||
@ -81,18 +79,18 @@ public class DefaultLinkingSystem implements PortalLinkingSystem {
 | 
				
			|||||||
            Vec3d fromCenter = new Vec3d((fromBox.getMaxX()+1 + fromBox.getMinX())/2D,(fromBox.getMaxY()+1 + fromBox.getMinY())/2D,(fromBox.getMaxZ()+1 + fromBox.getMinZ())/2D);
 | 
					            Vec3d fromCenter = new Vec3d((fromBox.getMaxX()+1 + fromBox.getMinX())/2D,(fromBox.getMaxY()+1 + fromBox.getMinY())/2D,(fromBox.getMaxZ()+1 + fromBox.getMinZ())/2D);
 | 
				
			||||||
            BlockBox toBox = toPortal.location();
 | 
					            BlockBox toBox = toPortal.location();
 | 
				
			||||||
            Vec3d toCenter = new Vec3d((toBox.getMaxX()+1 + toBox.getMinX())/2D,(toBox.getMaxY()+1 + toBox.getMinY())/2D,(toBox.getMaxZ()+1 + toBox.getMinZ())/2D);
 | 
					            Vec3d toCenter = new Vec3d((toBox.getMaxX()+1 + toBox.getMinX())/2D,(toBox.getMaxY()+1 + toBox.getMinY())/2D,(toBox.getMaxZ()+1 + toBox.getMinZ())/2D);
 | 
				
			||||||
            if (getAxisW(fromPortal.location()) == getAxisW(toPortal.location())) {
 | 
					            if (getAxisW(fromPortal) == getAxisW(toPortal)) {
 | 
				
			||||||
                Vec3d relPos = entity.getPos().subtract(fromCenter);
 | 
					                Vec3d relPos = entity.getPos().subtract(fromCenter);
 | 
				
			||||||
                Vec3d targetPos = toCenter.add(relPos);
 | 
					                Vec3d targetPos = toCenter.add(relPos);
 | 
				
			||||||
                //todo: maybe fancy continoous movement math!
 | 
					                //todo: maybe fancy continoous movement math!
 | 
				
			||||||
                ServerWorld toWorld = getPortalWorld(toPortal);
 | 
					                ServerWorld toWorld = getPortalWorld(server, toPortal);
 | 
				
			||||||
                TeleportTarget teleportTarget = new TeleportTarget(toWorld, targetPos, entity.getVelocity(), entity.getYaw(), entity.getPitch(), TeleportTarget.ADD_PORTAL_CHUNK_TICKET);
 | 
					                TeleportTarget teleportTarget = new TeleportTarget(toWorld, targetPos, entity.getVelocity(), entity.getYaw(), entity.getPitch(), TeleportTarget.ADD_PORTAL_CHUNK_TICKET);
 | 
				
			||||||
                entity.teleportTo(teleportTarget);
 | 
					                entity.teleportTo(teleportTarget);
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                Vec3d relPos = entity.getPos().subtract(fromCenter);
 | 
					                Vec3d relPos = entity.getPos().subtract(fromCenter);
 | 
				
			||||||
                Vec3d targetPos = toCenter.add(new Vec3d(-relPos.z, relPos.y, relPos.x));
 | 
					                Vec3d targetPos = toCenter.add(new Vec3d(-relPos.z, relPos.y, relPos.x));
 | 
				
			||||||
                //todo: maybe fancy continoous movement math!
 | 
					                //todo: maybe fancy continoous movement math!
 | 
				
			||||||
                ServerWorld toWorld = getPortalWorld(toPortal);
 | 
					                ServerWorld toWorld = getPortalWorld(server, toPortal);
 | 
				
			||||||
                TeleportTarget teleportTarget = new TeleportTarget(toWorld, targetPos, entity.getVelocity(), (entity.getYaw() + 90.F) % 360.F, entity.getPitch(), TeleportTarget.ADD_PORTAL_CHUNK_TICKET);
 | 
					                TeleportTarget teleportTarget = new TeleportTarget(toWorld, targetPos, entity.getVelocity(), (entity.getYaw() + 90.F) % 360.F, entity.getPitch(), TeleportTarget.ADD_PORTAL_CHUNK_TICKET);
 | 
				
			||||||
                entity.teleportTo(teleportTarget);
 | 
					                entity.teleportTo(teleportTarget);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -104,8 +102,8 @@ public class DefaultLinkingSystem implements PortalLinkingSystem {
 | 
				
			|||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private ServerWorld getPortalWorld(PortalRepresentation fromPortalRepresentation) {
 | 
					    private static ServerWorld getPortalWorld(MinecraftServer server, PortalRepresentation fromPortalRepresentation) {
 | 
				
			||||||
        ServerWorld serverWorld = server.getWorld(RegistryKey.of(RegistryKeys.WORLD, fromPortalRepresentation.dimensionId()));
 | 
					        ServerWorld serverWorld = PortalHelper.getPortalWorld(server, fromPortalRepresentation);
 | 
				
			||||||
        if (serverWorld == null) {
 | 
					        if (serverWorld == null) {
 | 
				
			||||||
            LOGGER.warn("couldn't get portal dimensionId for portal {}. Don't sue me!", fromPortalRepresentation);
 | 
					            LOGGER.warn("couldn't get portal dimensionId for portal {}. Don't sue me!", fromPortalRepresentation);
 | 
				
			||||||
            throw new RuntimeException();
 | 
					            throw new RuntimeException();
 | 
				
			||||||
 | 
				
			|||||||
@ -131,7 +131,7 @@ public class ImmersivePortalsLinkingSystem implements PortalLinkingSystem {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private ServerWorld getPortalWorld(PortalRepresentation fromPortalRepresentation) {
 | 
					    private ServerWorld getPortalWorld(PortalRepresentation fromPortalRepresentation) {
 | 
				
			||||||
        ServerWorld serverWorld = server.getWorld(RegistryKey.of(RegistryKeys.WORLD, fromPortalRepresentation.dimensionId()));
 | 
					        ServerWorld serverWorld = PortalHelper.getPortalWorld(server, fromPortalRepresentation);
 | 
				
			||||||
        if (serverWorld == null) {
 | 
					        if (serverWorld == null) {
 | 
				
			||||||
            LOGGER.warn("couldn't get portal dimensionId for portal {}. Don't sue me!", fromPortalRepresentation);
 | 
					            LOGGER.warn("couldn't get portal dimensionId for portal {}. Don't sue me!", fromPortalRepresentation);
 | 
				
			||||||
            throw new RuntimeException();
 | 
					            throw new RuntimeException();
 | 
				
			||||||
 | 
				
			|||||||
@ -3,12 +3,16 @@ package quimufu.colourful_portals.portal;
 | 
				
			|||||||
import net.minecraft.block.Block;
 | 
					import net.minecraft.block.Block;
 | 
				
			||||||
import net.minecraft.block.BlockState;
 | 
					import net.minecraft.block.BlockState;
 | 
				
			||||||
import net.minecraft.registry.Registries;
 | 
					import net.minecraft.registry.Registries;
 | 
				
			||||||
 | 
					import net.minecraft.registry.RegistryKey;
 | 
				
			||||||
 | 
					import net.minecraft.registry.RegistryKeys;
 | 
				
			||||||
 | 
					import net.minecraft.server.MinecraftServer;
 | 
				
			||||||
import net.minecraft.server.world.ServerWorld;
 | 
					import net.minecraft.server.world.ServerWorld;
 | 
				
			||||||
import net.minecraft.util.Identifier;
 | 
					import net.minecraft.util.Identifier;
 | 
				
			||||||
import net.minecraft.util.math.BlockBox;
 | 
					import net.minecraft.util.math.BlockBox;
 | 
				
			||||||
import net.minecraft.util.math.BlockPos;
 | 
					import net.minecraft.util.math.BlockPos;
 | 
				
			||||||
import net.minecraft.util.math.Direction;
 | 
					import net.minecraft.util.math.Direction;
 | 
				
			||||||
import net.minecraft.util.math.Vec3i;
 | 
					import net.minecraft.util.math.Vec3i;
 | 
				
			||||||
 | 
					import org.jetbrains.annotations.Nullable;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.*;
 | 
					import java.util.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -24,21 +28,21 @@ public class PortalHelper {
 | 
				
			|||||||
            {'N', 'X', 'X', 'N'},
 | 
					            {'N', 'X', 'X', 'N'},
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static Iterator<BlockPos> insideOf(BlockBox portal) {
 | 
					    static Iterator<BlockPos> insideOf(PortalRepresentation portal) {
 | 
				
			||||||
        Direction axisW = getAxisW(portal);
 | 
					        BlockBox portal1 = portal.location();
 | 
				
			||||||
 | 
					        Direction axisW = getAxisW(portal1);
 | 
				
			||||||
        Vec3i dir = axisW.getVector();
 | 
					        Vec3i dir = axisW.getVector();
 | 
				
			||||||
        BlockPos startPos = new BlockPos(portal.getMinX(), portal.getMinY(), portal.getMinZ());
 | 
					        BlockPos startPos = new BlockPos(portal1.getMinX(), portal1.getMinY(), portal1.getMinZ());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return new BlockPosIterator(startPos, dir, 'O');
 | 
					        return new BlockPosIterator(startPos, dir, 'O');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    static boolean isValidPortal(ServerWorld world, PortalRepresentation portal, Identifier blockId) {
 | 
				
			||||||
    static boolean isValidPortal(ServerWorld world, BlockBox portal, Identifier blockId) {
 | 
					        return isValidPortal(world, portal.location(), blockId, true, false);
 | 
				
			||||||
        return isValidPortal(world, portal, blockId, true, false);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static boolean isValidCandidate(ServerWorld world, BlockBox portal, Identifier blockId) {
 | 
					    static boolean isValidCandidate(ServerWorld world, PortalRepresentation portal, Identifier blockId) {
 | 
				
			||||||
        return isValidPortal(world, portal, blockId, false, false);
 | 
					        return isValidPortal(world, portal.location(), blockId, false, false);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static boolean isValidPortal(ServerWorld world, BlockBox portal, Identifier blockId, boolean empty, boolean placementCheck) {
 | 
					    private static boolean isValidPortal(ServerWorld world, BlockBox portal, Identifier blockId, boolean empty, boolean placementCheck) {
 | 
				
			||||||
@ -46,15 +50,19 @@ public class PortalHelper {
 | 
				
			|||||||
        return isValidPortal(world, Registries.BLOCK.get(blockId), new BlockPos(portal.getMinX(), portal.getMinY(), portal.getMinZ()), empty, axisW, placementCheck);
 | 
					        return isValidPortal(world, Registries.BLOCK.get(blockId), new BlockPos(portal.getMinX(), portal.getMinY(), portal.getMinZ()), empty, axisW, placementCheck);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    static Direction getAxisW(PortalRepresentation portalRepresentation) {
 | 
				
			||||||
 | 
					        return getAxisW(portalRepresentation.location());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static Direction getAxisW(BlockBox fromPortalBox) {
 | 
					    static Direction getAxisW(BlockBox fromPortalBox) {
 | 
				
			||||||
        if (fromPortalBox.getMaxX() - fromPortalBox.getMinX() > 2)
 | 
					        if (fromPortalBox.getMaxX() - fromPortalBox.getMinX() > 2)
 | 
				
			||||||
            return Direction.EAST;
 | 
					            return Direction.EAST;
 | 
				
			||||||
        return Direction.SOUTH;
 | 
					        return Direction.SOUTH;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    static List<BlockBox> findPortalCandidates(ServerWorld world, BlockPos pos, Identifier blockId) {
 | 
					    static List<PortalRepresentation> findPortalCandidates(ServerWorld world, BlockPos pos, Identifier blockId) {
 | 
				
			||||||
        Block block = Registries.BLOCK.get(blockId);
 | 
					        Block block = Registries.BLOCK.get(blockId);
 | 
				
			||||||
        ArrayList<BlockBox> portals = new ArrayList<>();
 | 
					        ArrayList<PortalRepresentation> portals = new ArrayList<>();
 | 
				
			||||||
        outer:
 | 
					        outer:
 | 
				
			||||||
        for (Direction direction : Direction.values()) {
 | 
					        for (Direction direction : Direction.values()) {
 | 
				
			||||||
            int size = direction == Direction.UP || direction == Direction.DOWN ? 5 : 4;
 | 
					            int size = direction == Direction.UP || direction == Direction.DOWN ? 5 : 4;
 | 
				
			||||||
@ -164,17 +172,18 @@ public class PortalHelper {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static Optional<BlockBox> getPortalStartingAt(ServerWorld world, Block block, BlockPos lowerCorner, Direction direction) {
 | 
					    private static Optional<PortalRepresentation> getPortalStartingAt(ServerWorld world, Block block, BlockPos lowerCorner, Direction direction) {
 | 
				
			||||||
        Vec3i sidewardsOffset = direction.getVector().multiply(3);
 | 
					        Vec3i sidewardsOffset = direction.getVector().multiply(3);
 | 
				
			||||||
        Vec3i upwardsOffset = Direction.UP.getVector().multiply(4);
 | 
					        Vec3i upwardsOffset = Direction.UP.getVector().multiply(4);
 | 
				
			||||||
        if (isValidPortal(world, block, lowerCorner, false, direction, false)) {
 | 
					        if (isValidPortal(world, block, lowerCorner, false, direction, false)) {
 | 
				
			||||||
            return Optional.of(BlockBox.create(lowerCorner, lowerCorner.add(sidewardsOffset).add(upwardsOffset)));
 | 
					            BlockBox location = BlockBox.create(lowerCorner, lowerCorner.add(sidewardsOffset).add(upwardsOffset));
 | 
				
			||||||
 | 
					            return Optional.of(new PortalRepresentation(location, getDimId(world)));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        return Optional.empty();
 | 
					        return Optional.empty();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static boolean isPortalPlaceable(ServerWorld world, BlockBox portal, Identifier blockId) {
 | 
					    public static boolean isPortalPlaceable(ServerWorld world, PortalRepresentation portal, Identifier blockId) {
 | 
				
			||||||
        return isValidPortal(world, portal, blockId, false, true);
 | 
					        return isValidPortal(world, portal.location(), blockId, false, true);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static boolean isValidPortal(ServerWorld world, Block block, BlockPos lowerCorner, boolean hasToBeFilledCorrectly, Direction direction, boolean placementCheck) {
 | 
					    private static boolean isValidPortal(ServerWorld world, Block block, BlockPos lowerCorner, boolean hasToBeFilledCorrectly, Direction direction, boolean placementCheck) {
 | 
				
			||||||
@ -212,6 +221,15 @@ public class PortalHelper {
 | 
				
			|||||||
        return true;
 | 
					        return true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Nullable
 | 
				
			||||||
 | 
					    public static ServerWorld getPortalWorld(MinecraftServer server, PortalRepresentation fromPortalRepresentation) {
 | 
				
			||||||
 | 
					        return server.getWorld(RegistryKey.of(RegistryKeys.WORLD, fromPortalRepresentation.dimensionId()));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static Identifier getDimId(ServerWorld world) {
 | 
				
			||||||
 | 
					        return world.getDimensionEntry().getKey().orElseThrow().getValue();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static class BlockPosIterator implements Iterator<BlockPos> {
 | 
					    private static class BlockPosIterator implements Iterator<BlockPos> {
 | 
				
			||||||
        private final BlockPos startPos;
 | 
					        private final BlockPos startPos;
 | 
				
			||||||
 | 
				
			|||||||
@ -3,8 +3,6 @@ package quimufu.colourful_portals.portal;
 | 
				
			|||||||
import net.minecraft.block.BlockState;
 | 
					import net.minecraft.block.BlockState;
 | 
				
			||||||
import net.minecraft.block.Blocks;
 | 
					import net.minecraft.block.Blocks;
 | 
				
			||||||
import net.minecraft.entity.Entity;
 | 
					import net.minecraft.entity.Entity;
 | 
				
			||||||
import net.minecraft.registry.RegistryKey;
 | 
					 | 
				
			||||||
import net.minecraft.registry.RegistryKeys;
 | 
					 | 
				
			||||||
import net.minecraft.server.MinecraftServer;
 | 
					import net.minecraft.server.MinecraftServer;
 | 
				
			||||||
import net.minecraft.server.world.ServerWorld;
 | 
					import net.minecraft.server.world.ServerWorld;
 | 
				
			||||||
import net.minecraft.util.DyeColor;
 | 
					import net.minecraft.util.DyeColor;
 | 
				
			||||||
@ -12,15 +10,14 @@ import net.minecraft.util.Identifier;
 | 
				
			|||||||
import net.minecraft.util.math.BlockBox;
 | 
					import net.minecraft.util.math.BlockBox;
 | 
				
			||||||
import net.minecraft.util.math.BlockPos;
 | 
					import net.minecraft.util.math.BlockPos;
 | 
				
			||||||
import net.minecraft.util.math.Direction;
 | 
					import net.minecraft.util.math.Direction;
 | 
				
			||||||
import org.jetbrains.annotations.Nullable;
 | 
					 | 
				
			||||||
import quimufu.colourful_portals.config.ColourfulPortalConfig;
 | 
					import quimufu.colourful_portals.config.ColourfulPortalConfig;
 | 
				
			||||||
import quimufu.colourful_portals.general_util.LinkedList;
 | 
					import quimufu.colourful_portals.general_util.LinkedList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.HashSet;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static quimufu.colourful_portals.ColourfulPortalsMod.*;
 | 
					import static quimufu.colourful_portals.ColourfulPortalsMod.*;
 | 
				
			||||||
import static quimufu.colourful_portals.Components.PORTAL_CANDIDATE_LIST;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class PortalManager {
 | 
					public class PortalManager {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -43,25 +40,24 @@ public class PortalManager {
 | 
				
			|||||||
        world.getProfiler().push("onPortalBlockPlaced");
 | 
					        world.getProfiler().push("onPortalBlockPlaced");
 | 
				
			||||||
        LOGGER.debug("onPortalBlockPlaced, {}", blockId);
 | 
					        LOGGER.debug("onPortalBlockPlaced, {}", blockId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        Identifier dimIdentifier = getDimId(world);
 | 
					        Identifier dimIdentifier = PortalHelper.getDimId(world);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        //delete portalCandidates obstructed by PortalBlocks for consistency
 | 
					        //delete portalCandidates obstructed by PortalBlocks for consistency
 | 
				
			||||||
        List<PortalRepresentation> portalCandidates = portalCandidateList.getContainingPortals(blockId, pos, dimIdentifier);
 | 
					        List<PortalRepresentation> portalCandidates = portalCandidateList.getContainingPortals(blockId, pos, dimIdentifier);
 | 
				
			||||||
        LOGGER.debug("got containing PortalCandidates , {}", portalCandidates);
 | 
					        LOGGER.debug("got containing PortalCandidates , {}", portalCandidates);
 | 
				
			||||||
        for (PortalRepresentation portalCandidate : portalCandidates) {
 | 
					        for (PortalRepresentation portalCandidate : portalCandidates) {
 | 
				
			||||||
            if (!PortalHelper.isValidCandidate(world, portalCandidate.location(), blockId)) {
 | 
					            if (!PortalHelper.isValidCandidate(world, portalCandidate, blockId)) {
 | 
				
			||||||
                LOGGER.debug("invalid, {}", portalCandidate);
 | 
					                LOGGER.debug("invalid, {}", portalCandidate);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                portalCandidateList.removePortal(blockId, portalCandidate);
 | 
					                portalCandidateList.removePortal(blockId, portalCandidate);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        //find new portalCandidates created by PortalBlock placement
 | 
					        //find new portalCandidates created by PortalBlock placement
 | 
				
			||||||
        List<BlockBox> portals = PortalHelper.findPortalCandidates(world, pos, blockId);
 | 
					        List<PortalRepresentation> portals = PortalHelper.findPortalCandidates(world, pos, blockId);
 | 
				
			||||||
        LOGGER.debug("new portalCandidates found, {}", portals);
 | 
					        LOGGER.debug("new portalCandidates found, {}", portals);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (BlockBox portal : portals) {
 | 
					        for (PortalRepresentation portal : portals) {
 | 
				
			||||||
            PortalRepresentation portalRepresentationWithDim = new PortalRepresentation(portal, dimIdentifier);
 | 
					            portalCandidateList.createPortal(blockId, portal);
 | 
				
			||||||
            portalCandidateList.createPortal(blockId, portalRepresentationWithDim);
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        world.getProfiler().pop();
 | 
					        world.getProfiler().pop();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -70,14 +66,12 @@ public class PortalManager {
 | 
				
			|||||||
        world.getProfiler().push("onPortalBlockBroken");
 | 
					        world.getProfiler().push("onPortalBlockBroken");
 | 
				
			||||||
        LOGGER.debug("onPortalBlockBroken, {}", blockId);
 | 
					        LOGGER.debug("onPortalBlockBroken, {}", blockId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        PortalListComponent portalCandidateList = PORTAL_CANDIDATE_LIST.get(world.getLevelProperties());
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        //check portalCandidate validity
 | 
					        //check portalCandidate validity
 | 
				
			||||||
        Identifier dimensionIdentifier = getDimId(world);
 | 
					        Identifier dimensionIdentifier = PortalHelper.getDimId(world);
 | 
				
			||||||
        List<PortalRepresentation> portalCandidates = portalCandidateList.getContainingPortals(blockId, pos, dimensionIdentifier);
 | 
					        List<PortalRepresentation> portalCandidates = portalCandidateList.getContainingPortals(blockId, pos, dimensionIdentifier);
 | 
				
			||||||
        LOGGER.debug("getContainingPortals, {}", portalCandidates);
 | 
					        LOGGER.debug("getContainingPortals, {}", portalCandidates);
 | 
				
			||||||
        for (PortalRepresentation portalCandidate : portalCandidates) {
 | 
					        for (PortalRepresentation portalCandidate : portalCandidates) {
 | 
				
			||||||
            if (!PortalHelper.isValidCandidate(world, portalCandidate.location(), blockId)) {
 | 
					            if (!PortalHelper.isValidCandidate(world, portalCandidate, blockId)) {
 | 
				
			||||||
                LOGGER.debug("invalid, {}", portalCandidate);
 | 
					                LOGGER.debug("invalid, {}", portalCandidate);
 | 
				
			||||||
                portalCandidateList.removePortal(blockId, portalCandidate);
 | 
					                portalCandidateList.removePortal(blockId, portalCandidate);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
@ -85,15 +79,11 @@ public class PortalManager {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        //add portalCandidates deobstructed by PortalBlock removal
 | 
					        //add portalCandidates deobstructed by PortalBlock removal
 | 
				
			||||||
        for (Direction direction : Direction.values()) {
 | 
					        for (Direction direction : Direction.values()) {
 | 
				
			||||||
            List<BlockBox> newPortalCandidates = PortalHelper.findPortalCandidates(world, pos.add(direction.getVector()), blockId);
 | 
					            List<PortalRepresentation> newPortalCandidates = PortalHelper.findPortalCandidates(world, pos.add(direction.getVector()), blockId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            for (BlockBox newPortal : newPortalCandidates) {
 | 
					            for (PortalRepresentation newPortal : newPortalCandidates) {
 | 
				
			||||||
                LOGGER.debug("potentially new candidate after deobstruction , {}", newPortal);
 | 
					                LOGGER.debug("potentially new candidate after deobstruction , {}", newPortal);
 | 
				
			||||||
 | 
					                portalCandidateList.createPortal(blockId, newPortal);
 | 
				
			||||||
                PortalListComponent portalListComponent = PORTAL_CANDIDATE_LIST.get(world.getLevelProperties());
 | 
					 | 
				
			||||||
                PortalRepresentation portalRepresentationWithDim =
 | 
					 | 
				
			||||||
                        new PortalRepresentation(newPortal, dimensionIdentifier);
 | 
					 | 
				
			||||||
                portalListComponent.createPortal(blockId, portalRepresentationWithDim);
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -102,7 +92,7 @@ public class PortalManager {
 | 
				
			|||||||
        List<PortalRepresentation> portals = portalList.getContainingPortals(blockId, pos, dimensionIdentifier);
 | 
					        List<PortalRepresentation> portals = portalList.getContainingPortals(blockId, pos, dimensionIdentifier);
 | 
				
			||||||
        boolean changed = false;
 | 
					        boolean changed = false;
 | 
				
			||||||
        for (PortalRepresentation portal : portals) {
 | 
					        for (PortalRepresentation portal : portals) {
 | 
				
			||||||
            if (!PortalHelper.isValidPortal(world, portal.location(), blockId)) {
 | 
					            if (!PortalHelper.isValidPortal(world, portal, blockId)) {
 | 
				
			||||||
                LOGGER.debug("portal became invalid ,{} {}", dimensionIdentifier, portal);
 | 
					                LOGGER.debug("portal became invalid ,{} {}", dimensionIdentifier, portal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                portalList.removePortal(blockId, portal);
 | 
					                portalList.removePortal(blockId, portal);
 | 
				
			||||||
@ -129,7 +119,7 @@ public class PortalManager {
 | 
				
			|||||||
        LinkedList<PortalRepresentation> portalsWithDim = portalList.getPortals(blockId);
 | 
					        LinkedList<PortalRepresentation> portalsWithDim = portalList.getPortals(blockId);
 | 
				
			||||||
        if (portalsWithDim.size() == 1) {
 | 
					        if (portalsWithDim.size() == 1) {
 | 
				
			||||||
            PortalRepresentation portalRepresentation = portalsWithDim.getFirst();
 | 
					            PortalRepresentation portalRepresentation = portalsWithDim.getFirst();
 | 
				
			||||||
            ServerWorld world = getPortalWorld(portalRepresentation, server);
 | 
					            ServerWorld world = PortalHelper.getPortalWorld(server, portalRepresentation);
 | 
				
			||||||
            if (world == null) {
 | 
					            if (world == null) {
 | 
				
			||||||
                LOGGER.error("error fixing portalGroup, dimensionId {} was null", portalRepresentation.dimensionId());
 | 
					                LOGGER.error("error fixing portalGroup, dimensionId {} was null", portalRepresentation.dimensionId());
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
@ -149,17 +139,17 @@ public class PortalManager {
 | 
				
			|||||||
    private void assurePortalBlocksPlaced(Identifier blockId, PortalRepresentation portalRepresentation, MinecraftServer server) {
 | 
					    private void assurePortalBlocksPlaced(Identifier blockId, PortalRepresentation portalRepresentation, MinecraftServer server) {
 | 
				
			||||||
        DyeColor color = ColourfulPortalConfig.colorOf(blockId.toString());
 | 
					        DyeColor color = ColourfulPortalConfig.colorOf(blockId.toString());
 | 
				
			||||||
        if (color != null) {
 | 
					        if (color != null) {
 | 
				
			||||||
            Direction.Axis portalPlaneAxis = PortalHelper.getAxisW(portalRepresentation.location())
 | 
					            Direction.Axis portalPlaneAxis = PortalHelper.getAxisW(portalRepresentation)
 | 
				
			||||||
                    .rotateClockwise(Direction.Axis.Y)
 | 
					                    .rotateClockwise(Direction.Axis.Y)
 | 
				
			||||||
                    .getAxis();
 | 
					                    .getAxis();
 | 
				
			||||||
            ServerWorld portalWorld = getPortalWorld(portalRepresentation, server);
 | 
					            ServerWorld portalWorld = PortalHelper.getPortalWorld(server, portalRepresentation);
 | 
				
			||||||
            if (portalWorld == null) {
 | 
					            if (portalWorld == null) {
 | 
				
			||||||
                LOGGER.error("error placing portalRepresentation planes, dimensionId {} was null", portalRepresentation.dimensionId());
 | 
					                LOGGER.error("error placing portalRepresentation planes, dimensionId {} was null", portalRepresentation.dimensionId());
 | 
				
			||||||
                return;
 | 
					                return;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            BlockState portalBlockState = PORTAL_BLOCK.getStateWith(color, portalPlaneAxis);
 | 
					            BlockState portalBlockState = PORTAL_BLOCK.getStateWith(color, portalPlaneAxis);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            PortalHelper.insideOf(portalRepresentation.location())
 | 
					            PortalHelper.insideOf(portalRepresentation)
 | 
				
			||||||
                    .forEachRemaining(blockPos -> {
 | 
					                    .forEachRemaining(blockPos -> {
 | 
				
			||||||
                        BlockState blockState = portalWorld.getBlockState(blockPos);
 | 
					                        BlockState blockState = portalWorld.getBlockState(blockPos);
 | 
				
			||||||
                        if (blockState.isAir() || blockState.getFluidState().isOf(PORTAL_FLUID)) {
 | 
					                        if (blockState.isAir() || blockState.getFluidState().isOf(PORTAL_FLUID)) {
 | 
				
			||||||
@ -174,26 +164,21 @@ public class PortalManager {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Nullable
 | 
					 | 
				
			||||||
    private ServerWorld getPortalWorld(PortalRepresentation fromPortalRepresentation, MinecraftServer server) {
 | 
					 | 
				
			||||||
        return server.getWorld(RegistryKey.of(RegistryKeys.WORLD, fromPortalRepresentation.dimensionId()));
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public boolean tryIgnite(ServerWorld world, BlockPos pos) {
 | 
					    public boolean tryIgnite(ServerWorld world, BlockPos pos) {
 | 
				
			||||||
        world.getProfiler().push("portal ignition");
 | 
					        world.getProfiler().push("portal ignition");
 | 
				
			||||||
        LOGGER.info("portal ignition");
 | 
					        LOGGER.info("portal ignition");
 | 
				
			||||||
        Set<Identifier> blockIds = portalCandidateList.getBlockIds();
 | 
					        Set<Identifier> blockIds = portalCandidateList.getBlockIds();
 | 
				
			||||||
        boolean ret = false;
 | 
					        boolean ret = false;
 | 
				
			||||||
        for (Identifier blockId : blockIds) {
 | 
					        for (Identifier blockId : blockIds) {
 | 
				
			||||||
            Identifier dim = getDimId(world);
 | 
					            Identifier dim = PortalHelper.getDimId(world);
 | 
				
			||||||
            List<PortalRepresentation> portalCandidates = portalCandidateList.getContainingPortals(blockId, pos, dim);
 | 
					            List<PortalRepresentation> portalCandidates = portalCandidateList.getContainingPortals(blockId, pos, dim);
 | 
				
			||||||
            for (PortalRepresentation current : portalCandidates) {
 | 
					            for (PortalRepresentation current : portalCandidates) {
 | 
				
			||||||
                if (PortalHelper.isValidPortal(world, current.location(), blockId)) {
 | 
					                if (PortalHelper.isValidPortal(world, current, blockId)) {
 | 
				
			||||||
                    PortalRepresentation next = portalCandidateList.getNext(blockId, current);
 | 
					                    PortalRepresentation next = portalCandidateList.getNext(blockId, current);
 | 
				
			||||||
                    ServerWorld nextWorld = getPortalWorld(next, world.getServer());
 | 
					                    ServerWorld nextWorld = PortalHelper.getPortalWorld(world.getServer(), next);
 | 
				
			||||||
                    if (!next.equals(current)
 | 
					                    if (!next.equals(current)
 | 
				
			||||||
                        && (!portalList.containsPortal(blockId, current) || !portalList.containsPortal(blockId, next))
 | 
					                        && (!portalList.containsPortal(blockId, current) || !portalList.containsPortal(blockId, next))
 | 
				
			||||||
                        && PortalHelper.isPortalPlaceable(nextWorld, next.location(), blockId)) {
 | 
					                        && PortalHelper.isPortalPlaceable(nextWorld, next, blockId)) {
 | 
				
			||||||
                        portalList.createPortal(blockId, current);
 | 
					                        portalList.createPortal(blockId, current);
 | 
				
			||||||
                        portalList.createPortal(blockId, next);
 | 
					                        portalList.createPortal(blockId, next);
 | 
				
			||||||
                        ret = true;
 | 
					                        ret = true;
 | 
				
			||||||
@ -209,18 +194,18 @@ public class PortalManager {
 | 
				
			|||||||
    public boolean canExtend(ServerWorld world, BlockPos pos) {
 | 
					    public boolean canExtend(ServerWorld world, BlockPos pos) {
 | 
				
			||||||
        world.getProfiler().push("portal extension check");
 | 
					        world.getProfiler().push("portal extension check");
 | 
				
			||||||
        Set<Identifier> blockIds = portalList.getBlockIds();
 | 
					        Set<Identifier> blockIds = portalList.getBlockIds();
 | 
				
			||||||
        Identifier dim = getDimId(world);
 | 
					        Identifier dim = PortalHelper.getDimId(world);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (Identifier blockId : blockIds) {
 | 
					        for (Identifier blockId : blockIds) {
 | 
				
			||||||
            List<PortalRepresentation> portals = portalList.getContainingPortals(blockId, pos, dim);
 | 
					            List<PortalRepresentation> portals = portalList.getContainingPortals(blockId, pos, dim);
 | 
				
			||||||
            for (PortalRepresentation portal : portals) {
 | 
					            for (PortalRepresentation portal : portals) {
 | 
				
			||||||
                if (PortalHelper.isValidPortal(world, portal.location(), blockId)) {
 | 
					                if (PortalHelper.isValidPortal(world, portal, blockId)) {
 | 
				
			||||||
                    PortalRepresentation last = portalList.getLast(blockId);
 | 
					                    PortalRepresentation last = portalList.getLast(blockId);
 | 
				
			||||||
                    PortalRepresentation next = portalCandidateList.getNext(blockId, last);
 | 
					                    PortalRepresentation next = portalCandidateList.getNext(blockId, last);
 | 
				
			||||||
                    ServerWorld nextWorld = getPortalWorld(next, world.getServer());
 | 
					                    ServerWorld nextWorld = PortalHelper.getPortalWorld(world.getServer(), next);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (!portalList.containsPortal(blockId, next)
 | 
					                    if (!portalList.containsPortal(blockId, next)
 | 
				
			||||||
                        && PortalHelper.isPortalPlaceable(nextWorld, next.location(), blockId)) {
 | 
					                        && PortalHelper.isPortalPlaceable(nextWorld, next, blockId)) {
 | 
				
			||||||
                        world.getProfiler().pop();
 | 
					                        world.getProfiler().pop();
 | 
				
			||||||
                        return true;
 | 
					                        return true;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -236,19 +221,19 @@ public class PortalManager {
 | 
				
			|||||||
    public boolean extend(ServerWorld world, BlockPos pos) {
 | 
					    public boolean extend(ServerWorld world, BlockPos pos) {
 | 
				
			||||||
        world.getProfiler().push("portal extension");
 | 
					        world.getProfiler().push("portal extension");
 | 
				
			||||||
        Set<Identifier> blockIds = portalList.getBlockIds();
 | 
					        Set<Identifier> blockIds = portalList.getBlockIds();
 | 
				
			||||||
        Identifier dim = getDimId(world);
 | 
					        Identifier dim = PortalHelper.getDimId(world);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        boolean ret = false;
 | 
					        boolean ret = false;
 | 
				
			||||||
        for (Identifier blockId : blockIds) {
 | 
					        for (Identifier blockId : blockIds) {
 | 
				
			||||||
            List<PortalRepresentation> portals = portalList.getContainingPortals(blockId, pos, dim);
 | 
					            List<PortalRepresentation> portals = portalList.getContainingPortals(blockId, pos, dim);
 | 
				
			||||||
            for (PortalRepresentation portal : portals) {
 | 
					            for (PortalRepresentation portal : portals) {
 | 
				
			||||||
                if (PortalHelper.isValidPortal(world, portal.location(), blockId)) {
 | 
					                if (PortalHelper.isValidPortal(world, portal, blockId)) {
 | 
				
			||||||
                    PortalRepresentation last = portalList.getLast(blockId);
 | 
					                    PortalRepresentation last = portalList.getLast(blockId);
 | 
				
			||||||
                    PortalRepresentation next = portalCandidateList.getNext(blockId, last);
 | 
					                    PortalRepresentation next = portalCandidateList.getNext(blockId, last);
 | 
				
			||||||
                    ServerWorld nextWorld = getPortalWorld(next, world.getServer());
 | 
					                    ServerWorld nextWorld = PortalHelper.getPortalWorld(world.getServer(), next);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (!portalList.containsPortal(blockId, next)
 | 
					                    if (!portalList.containsPortal(blockId, next)
 | 
				
			||||||
                        && PortalHelper.isPortalPlaceable(nextWorld, next.location(), blockId)) {
 | 
					                        && PortalHelper.isPortalPlaceable(nextWorld, next, blockId)) {
 | 
				
			||||||
                        portalList.createPortal(blockId, next);
 | 
					                        portalList.createPortal(blockId, next);
 | 
				
			||||||
                        ret = true;
 | 
					                        ret = true;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
@ -262,11 +247,28 @@ public class PortalManager {
 | 
				
			|||||||
        return ret;
 | 
					        return ret;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static Identifier getDimId(ServerWorld world) {
 | 
					 | 
				
			||||||
        return world.getDimensionEntry().getKey().orElseThrow().getValue();
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public void onPortalPassed(Entity entity, BlockPos pos, ServerWorld world, Direction.Axis a) {
 | 
					    public void onPortalPassed(Entity entity, BlockPos pos, ServerWorld world, Direction.Axis a) {
 | 
				
			||||||
        linkingSystem.onPortalPassed(entity, pos, world, a);
 | 
					        linkingSystem.onPortalPassed(entity, pos, world, a);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public void onLoad(MinecraftServer minecraftServer) {
 | 
				
			||||||
 | 
					        HashSet<Identifier> blockIdsToDelete = new HashSet<>(portalCandidateList.getBlockIds());
 | 
				
			||||||
 | 
					        blockIdsToDelete.addAll(portalList.getBlockIds());
 | 
				
			||||||
 | 
					        blockIdsToDelete.removeAll(PORTAL_BLOCKS);
 | 
				
			||||||
 | 
					        for (Identifier blockId : blockIdsToDelete) {
 | 
				
			||||||
 | 
					            for (PortalRepresentation portal : portalCandidateList.getPortals(blockId)) {
 | 
				
			||||||
 | 
					                portalCandidateList.removePortal(blockId, portal);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            for (PortalRepresentation portal : portalList.getPortals(blockId)) {
 | 
				
			||||||
 | 
					                portalList.removePortal(blockId, portal);
 | 
				
			||||||
 | 
					                linkingSystem.unLinkPortal(portal);
 | 
				
			||||||
 | 
					                ServerWorld portalWorld = PortalHelper.getPortalWorld(minecraftServer, portal);
 | 
				
			||||||
 | 
					                if (portalWorld != null) {
 | 
				
			||||||
 | 
					                    removePortalBlocks(portalWorld, portal.location());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user