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);
});
}
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;
}
Aggregations