Portal search function fix. Portals now work as intended

This commit is contained in:
paulevsGitch 2021-01-05 02:39:55 +03:00
parent c240576185
commit c394f5a5f0

View file

@ -22,6 +22,7 @@ import net.minecraft.util.registry.Registry;
import net.minecraft.world.Heightmap; import net.minecraft.world.Heightmap;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldAccess;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.dimension.DimensionType; import net.minecraft.world.dimension.DimensionType;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
@ -102,31 +103,37 @@ public class EndPortalBlock extends NetherPortalBlock implements IRenderTypeable
BlockPos.Mutable checkPos = basePos.mutableCopy(); BlockPos.Mutable checkPos = basePos.mutableCopy();
for (int step = 1; step < 128; step++) { for (int step = 1; step < 128; step++) {
for (int i = 0; i < (step >> 1); i++) { for (int i = 0; i < (step >> 1); i++) {
checkPos.setY(5); Chunk chunk = world.getChunk(checkPos);
int ceil = world.getChunk(basePos).sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX(), checkPos.getZ()) + 1; if (chunk != null) {
if (ceil < 5) continue; int ceil = chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, checkPos.getX() & 15, checkPos.getZ() & 15);
while(checkPos.getY() < ceil) { if (ceil > 5) {
BlockState state = world.getBlockState(checkPos); checkPos.setY(ceil);
if(state.isOf(this)) { while (checkPos.getY() > 5) {
Axis axis = state.get(AXIS); BlockState state = world.getBlockState(checkPos);
checkPos = this.findCenter(world, checkPos, axis); if (state.isOf(this)) {
System.out.println("Out: " + checkPos);
Direction frontDir = Direction.from(axis, AxisDirection.POSITIVE).rotateYClockwise(); Axis axis = state.get(AXIS);
Direction entityDir = entity.getMovementDirection(); checkPos = this.findCenter(world, checkPos, axis);
if (entityDir.getAxis().isVertical()) {
entityDir = frontDir;
}
if (frontDir == entityDir || frontDir.getOpposite() == entityDir) { Direction frontDir = Direction.from(axis, AxisDirection.POSITIVE).rotateYClockwise();
return checkPos.offset(entityDir); Direction entityDir = entity.getMovementDirection();
} if (entityDir.getAxis().isVertical()) {
else { entityDir = frontDir;
entity.applyRotation(BlockRotation.CLOCKWISE_90); }
entityDir = entityDir.rotateYClockwise();
return checkPos.offset(entityDir); if (frontDir == entityDir || frontDir.getOpposite() == entityDir) {
return checkPos.offset(entityDir);
}
else {
entity.applyRotation(BlockRotation.CLOCKWISE_90);
entityDir = entityDir.rotateYClockwise();
return checkPos.offset(entityDir);
}
}
checkPos.move(Direction.DOWN);
} }
} }
checkPos.move(Direction.UP);
} }
checkPos.move(direction); checkPos.move(direction);
} }