Search in sources :

Example 1 with LoadingIndicatorEntity

use of com.qouteall.immersive_portals.portal.LoadingIndicatorEntity in project ImmersivePortalsMod by qouteall.

the class MyNetworkClient method processSpawnLoadingIndicator.

private static void processSpawnLoadingIndicator(PacketContext context, PacketByteBuf buf) {
    DimensionType dimension = DimensionType.byRawId(buf.readInt());
    Vec3d pos = new Vec3d(buf.readDouble(), buf.readDouble(), buf.readDouble());
    MinecraftClient.getInstance().execute(() -> {
        ClientWorld world = CGlobal.clientWorldLoader.getWorld(dimension);
        if (world == null) {
            return;
        }
        LoadingIndicatorEntity indicator = new LoadingIndicatorEntity(world);
        indicator.setPosition(pos.x, pos.y, pos.z);
        world.addEntity(233333333, indicator);
    });
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) LoadingIndicatorEntity(com.qouteall.immersive_portals.portal.LoadingIndicatorEntity) IEClientWorld(com.qouteall.immersive_portals.ducks.IEClientWorld) ClientWorld(net.minecraft.client.world.ClientWorld) Vec3d(net.minecraft.util.math.Vec3d)

Example 2 with LoadingIndicatorEntity

use of com.qouteall.immersive_portals.portal.LoadingIndicatorEntity in project ImmersivePortalsMod by qouteall.

the class NewNetherPortalGenerator method onFireLit.

// return null for not found
// executed on main server thread
public static boolean onFireLit(ServerWorld fromWorld, BlockPos firePos) {
    DimensionType fromDimension = fromWorld.dimension.getType();
    DimensionType toDimension = NetherPortalGenerator.getDestinationDimension(fromDimension);
    if (toDimension == null)
        return false;
    NetherPortalShape foundShape = Arrays.stream(Direction.Axis.values()).map(axis -> NetherPortalShape.findArea(firePos, axis, blockPos -> NetherPortalMatcher.isAirOrFire(fromWorld, blockPos), blockPos -> NetherPortalMatcher.isObsidian(fromWorld, blockPos))).filter(Objects::nonNull).findFirst().orElse(null);
    if (foundShape == null) {
        return false;
    }
    NetherPortalShape fromShape = foundShape;
    ServerWorld toWorld = McHelper.getServer().getWorld(toDimension);
    BlockPos fromPos = fromShape.innerAreaBox.getCenter();
    boolean isOtherGenerationRunning = McHelper.getEntitiesNearby(fromWorld, new Vec3d(fromPos), LoadingIndicatorEntity.class, 1).findAny().isPresent();
    if (isOtherGenerationRunning) {
        return false;
    }
    BlockPos toPos = NetherPortalGenerator.getPosInOtherDimension(fromPos, fromWorld.dimension.getType(), toWorld.dimension.getType());
    // avoid blockpos object creation
    BlockPos.Mutable temp = new BlockPos.Mutable();
    IntegerAABBInclusive toWorldHeightLimit = NetherPortalMatcher.getHeightLimit(toWorld.dimension.getType());
    Iterator<NetherPortalShape> iterator = NetherPortalMatcher.fromNearToFarWithinHeightLimit(toPos, 150, toWorldHeightLimit).map(blockPos -> {
        if (!toWorld.isAir(blockPos)) {
            return null;
        }
        return fromShape.matchShape(toWorld::isAir, p -> NetherPortalMatcher.isObsidian(toWorld, p), blockPos, temp);
    }).iterator();
    LoadingIndicatorEntity indicatorEntity = LoadingIndicatorEntity.entityType.create(fromWorld);
    indicatorEntity.isAlive = true;
    indicatorEntity.setPosition(fromPos.getX() + 0.5, fromPos.getY() + 0.5, fromPos.getZ() + 0.5);
    fromWorld.spawnEntity(indicatorEntity);
    McHelper.performSplitedFindingTaskOnServer(iterator, Objects::nonNull, (i) -> {
        boolean isIntact = recheckTheFrameThatIsBeingLighted(fromWorld, fromShape);
        if ((!isIntact)) {
            Helper.log("Nether Portal Generation Aborted");
            indicatorEntity.remove();
            return false;
        }
        double progress = i / 20000000.0;
        indicatorEntity.setText("Searching for matched obsidian frame on the other side\n" + (int) (progress * 100) + "%");
        return true;
    }, toShape -> {
        finishGeneratingPortal(new Info(fromDimension, toDimension, fromShape, toShape));
    }, () -> {
        indicatorEntity.setText("Existing frame could not be found.\n" + "Generating new portal");
        ModMain.serverTaskList.addTask(() -> {
            IntegerAABBInclusive airCubePlacement = NetherPortalGenerator.findAirCubePlacement(toWorld, toPos, toWorldHeightLimit, fromShape.axis, fromShape.totalAreaBox.getSize());
            NetherPortalShape toShape = fromShape.getShapeWithMovedAnchor(airCubePlacement.l.subtract(fromShape.totalAreaBox.l).add(fromShape.anchor));
            toShape.frameAreaWithCorner.forEach(blockPos -> toWorld.setBlockState(blockPos, Blocks.OBSIDIAN.getDefaultState()));
            finishGeneratingPortal(new Info(fromDimension, toDimension, fromShape, toShape));
            return true;
        });
    });
    return true;
}
Also used : Arrays(java.util.Arrays) Iterator(java.util.Iterator) ServerWorld(net.minecraft.server.world.ServerWorld) BlockPos(net.minecraft.util.math.BlockPos) Helper(com.qouteall.immersive_portals.Helper) IntegerAABBInclusive(com.qouteall.immersive_portals.my_util.IntegerAABBInclusive) Blocks(net.minecraft.block.Blocks) Direction(net.minecraft.util.math.Direction) Objects(java.util.Objects) McHelper(com.qouteall.immersive_portals.McHelper) ModMain(com.qouteall.immersive_portals.ModMain) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) DimensionType(net.minecraft.world.dimension.DimensionType) PortalPlaceholderBlock(com.qouteall.immersive_portals.portal.PortalPlaceholderBlock) LoadingIndicatorEntity(com.qouteall.immersive_portals.portal.LoadingIndicatorEntity) DimensionType(net.minecraft.world.dimension.DimensionType) IntegerAABBInclusive(com.qouteall.immersive_portals.my_util.IntegerAABBInclusive) Vec3d(net.minecraft.util.math.Vec3d) ServerWorld(net.minecraft.server.world.ServerWorld) LoadingIndicatorEntity(com.qouteall.immersive_portals.portal.LoadingIndicatorEntity) Objects(java.util.Objects) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

LoadingIndicatorEntity (com.qouteall.immersive_portals.portal.LoadingIndicatorEntity)2 Vec3d (net.minecraft.util.math.Vec3d)2 DimensionType (net.minecraft.world.dimension.DimensionType)2 Helper (com.qouteall.immersive_portals.Helper)1 McHelper (com.qouteall.immersive_portals.McHelper)1 ModMain (com.qouteall.immersive_portals.ModMain)1 IEClientWorld (com.qouteall.immersive_portals.ducks.IEClientWorld)1 IntegerAABBInclusive (com.qouteall.immersive_portals.my_util.IntegerAABBInclusive)1 PortalPlaceholderBlock (com.qouteall.immersive_portals.portal.PortalPlaceholderBlock)1 Arrays (java.util.Arrays)1 Iterator (java.util.Iterator)1 Objects (java.util.Objects)1 Block (net.minecraft.block.Block)1 Blocks (net.minecraft.block.Blocks)1 ClientWorld (net.minecraft.client.world.ClientWorld)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 BlockPos (net.minecraft.util.math.BlockPos)1 Direction (net.minecraft.util.math.Direction)1