Targeted portals (WIP, bugged)

This commit is contained in:
Aleksey 2021-03-07 22:50:25 +03:00
parent 83fd4603ac
commit e12ec53c01
2 changed files with 11 additions and 6 deletions

View file

@ -87,8 +87,8 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
ServerWorld currentWorld = (ServerWorld) world; ServerWorld currentWorld = (ServerWorld) world;
MinecraftServer server = currentWorld.getServer(); MinecraftServer server = currentWorld.getServer();
ServerWorld targetWorld = EndPortals.getWorld(server, state.get(PORTAL)); ServerWorld targetWorld = EndPortals.getWorld(server, state.get(PORTAL));
boolean isTarget = world.getRegistryKey().equals(targetWorld.getRegistryKey()); boolean isInEnd = currentWorld.getRegistryKey().equals(World.END);
ServerWorld destination = isTarget ? server.getWorld(World.END) : targetWorld; ServerWorld destination = isInEnd ? targetWorld : server.getWorld(World.END);
BlockPos exitPos = findExitPos(currentWorld, destination, pos, entity); BlockPos exitPos = findExitPos(currentWorld, destination, pos, entity);
if (exitPos == null) return; if (exitPos == null) return;
if (entity instanceof ServerPlayerEntity) { if (entity instanceof ServerPlayerEntity) {
@ -129,9 +129,8 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
Identifier currentWorldId = current.getRegistryKey().getValue(); Identifier currentWorldId = current.getRegistryKey().getValue();
double targetMultiplier = Objects.requireNonNull(registry.get(targetWorldId)).getCoordinateScale(); double targetMultiplier = Objects.requireNonNull(registry.get(targetWorldId)).getCoordinateScale();
double currentMultiplier = Objects.requireNonNull(registry.get(currentWorldId)).getCoordinateScale(); double currentMultiplier = Objects.requireNonNull(registry.get(currentWorldId)).getCoordinateScale();
double multiplier = targetMultiplier > currentMultiplier ? currentMultiplier / targetMultiplier : currentMultiplier; double multiplier = targetMultiplier > currentMultiplier ? 1.0 / targetMultiplier : currentMultiplier;
BlockPos.Mutable basePos = pos.mutableCopy().set(pos.getX() * multiplier, pos.getY(), pos.getZ() * multiplier); BlockPos.Mutable basePos = pos.mutableCopy().set(pos.getX() * multiplier, pos.getY(), pos.getZ() * multiplier);
System.out.println(basePos);
Direction direction = Direction.EAST; Direction direction = Direction.EAST;
BlockPos.Mutable checkPos = basePos.mutableCopy(); BlockPos.Mutable checkPos = basePos.mutableCopy();
for (int step = 1; step < 128; step++) { for (int step = 1; step < 128; step++) {

View file

@ -143,7 +143,6 @@ public class EternalRitual {
private void activatePortal(Item item) { private void activatePortal(Item item) {
if (active) return; if (active) return;
int state = EndPortals.getPortalState(Registry.ITEM.getId(item)); int state = EndPortals.getPortalState(Registry.ITEM.getId(item));
System.out.println(state);
activatePortal(world, center, state); activatePortal(world, center, state);
doEffects((ServerWorld) world, center); doEffects((ServerWorld) world, center);
if (exit == null) { if (exit == null) {
@ -217,12 +216,15 @@ public class EternalRitual {
public void removePortal(int state) { public void removePortal(int state) {
if (!active || isInvalid()) return; if (!active || isInvalid()) return;
System.out.println(getTargetWorld(state).getRegistryKey());
System.out.println(exit);
removePortal(getTargetWorld(state), exit); removePortal(getTargetWorld(state), exit);
removePortal(world, center); removePortal(world, center);
} }
private void removePortal(World world, BlockPos center) { private void removePortal(World world, BlockPos center) {
BlockPos framePos = center.down(); BlockPos framePos = center.down();
System.out.println(framePos);
Direction moveDir = Direction.Axis.X == axis ? Direction.NORTH : Direction.EAST; Direction moveDir = Direction.Axis.X == axis ? Direction.NORTH : Direction.EAST;
FRAME_MAP.forEach(point -> { FRAME_MAP.forEach(point -> {
BlockPos pos = framePos.mutableCopy().move(moveDir, point.x).move(Direction.UP, point.y); BlockPos pos = framePos.mutableCopy().move(moveDir, point.x).move(Direction.UP, point.y);
@ -258,6 +260,7 @@ public class EternalRitual {
double multiplier = Objects.requireNonNull(registry.get(targetWorldId)).getCoordinateScale(); double multiplier = Objects.requireNonNull(registry.get(targetWorldId)).getCoordinateScale();
BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / multiplier, center.getY(), center.getZ() / multiplier); BlockPos.Mutable basePos = center.mutableCopy().set(center.getX() / multiplier, center.getY(), center.getZ() / multiplier);
Direction.Axis portalAxis = (Direction.Axis.X == axis) ? Direction.Axis.Z : Direction.Axis.X; Direction.Axis portalAxis = (Direction.Axis.X == axis) ? Direction.Axis.Z : Direction.Axis.X;
int worldCeil = targetWorld.getDimensionHeight() - 1;
if (checkIsAreaValid(targetWorld, basePos, portalAxis)) { if (checkIsAreaValid(targetWorld, basePos, portalAxis)) {
EternalRitual.generatePortal(targetWorld, basePos, portalAxis); EternalRitual.generatePortal(targetWorld, basePos, portalAxis);
return basePos.toImmutable(); return basePos.toImmutable();
@ -269,7 +272,8 @@ public class EternalRitual {
Chunk chunk = world.getChunk(checkPos); Chunk chunk = world.getChunk(checkPos);
if (chunk != null) { if (chunk != null) {
int ceil = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX() & 15, checkPos.getZ() & 15) + 1; int ceil = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX() & 15, checkPos.getZ() & 15) + 1;
if (ceil < 2) continue; ceil = Math.min(ceil, worldCeil);
if (ceil < 5) continue;
checkPos.setY(ceil); checkPos.setY(ceil);
while (checkPos.getY() > 2) { while (checkPos.getY() > 2) {
if(checkIsAreaValid(targetWorld, checkPos, portalAxis)) { if(checkIsAreaValid(targetWorld, checkPos, portalAxis)) {
@ -303,6 +307,8 @@ public class EternalRitual {
} }
private boolean checkIsAreaValid(World world, BlockPos pos, Direction.Axis axis) { private boolean checkIsAreaValid(World world, BlockPos pos, Direction.Axis axis) {
System.out.println(pos.getY());
if (pos.getY() >= world.getDimensionHeight() - 1) return false;
if (!isBaseValid(world, pos, axis)) return false; if (!isBaseValid(world, pos, axis)) return false;
return EternalRitual.checkArea(world, pos, axis); return EternalRitual.checkArea(world, pos, axis);
} }