Skip to content

Commit

Permalink
Unhardcode world heights
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEpicBlock committed Jun 13, 2021
1 parent 28e3204 commit 5c9364d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void tick(int tickCount) {
});

//go through all blocks in this layer and use the transformProfile to get the correct block in the nether. Then send it to the client
rect2.iterateClamped(player.getPos(), config.horizontalSendLimit, (pos) -> {
rect2.iterateClamped(player.getPos(), config.horizontalSendLimit, Util.min(sourceWorld, destinationWorld), (pos) -> {
double dist = Util.getDistance(pos, portal.getLowerLeft());
if (dist > config.squaredAtmosphereRadiusPlusOne) return;

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/nl/theepicblock/immersive_cursedness/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.*;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.ChunkStatus;
Expand Down Expand Up @@ -159,4 +160,10 @@ public static double getDistance(BlockPos a, BlockPos b) {
public static PlayerManager getManagerFromPlayer(ServerPlayerEntity player) {
return ImmersiveCursedness.cursednessServer.getManager(player);
}

public static WorldHeights min(HeightLimitView a, HeightLimitView b) {
return new WorldHeights(Math.max(a.getBottomY(), b.getBottomY()), Math.min(a.getTopY(), b.getTopY()));
}

public record WorldHeights(int min, int max) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.HeightLimitView;
import net.minecraft.world.World;
import nl.theepicblock.immersive_cursedness.Util;

import java.util.function.Consumer;
Expand Down Expand Up @@ -47,14 +49,14 @@ public BlockPos getTopRightBlock() {
return createBlockPos(top-1, right-1);
}

public BlockPos getBottomLeftBlockClamped(Vec3d center, int limit) {
public BlockPos getBottomLeftBlockClamped(Vec3d center, int limit, HeightLimitView world) {
double centerP = Util.get(center, Util.rotate(axis));
return createBlockPos(clamp(bottom,0,255), clamp(left,centerP-limit,centerP+limit));
return createBlockPos(clamp(bottom, world.getBottomY(), world.getTopY()), clamp(left,centerP-limit,centerP+limit));
}

public BlockPos getTopRightBlockClamped(Vec3d center, int limit) {
public BlockPos getTopRightBlockClamped(Vec3d center, int limit, HeightLimitView world) {
double centerP = Util.get(center, Util.rotate(axis));
return createBlockPos(clamp(top-1,0,255), clamp(right-1,centerP-limit,centerP+limit));
return createBlockPos(clamp(top-1, world.getBottomY(), world.getTopY()), clamp(right-1,centerP-limit,centerP+limit));
}

public FlatStandingRectangle expand(int i, Vec3d source) {
Expand Down Expand Up @@ -98,12 +100,12 @@ public boolean isBeside(Vec3d pos) {
Util.get(pos, axis) > this.other;
}

public void iterateClamped(Vec3d center, int limit, Consumer<BlockPos> predicate) {
public void iterateClamped(Vec3d center, int limit, Util.WorldHeights world, Consumer<BlockPos> predicate) {
double centerP = Util.get(center, Util.rotate(axis));
int left = (int)Math.round(clamp(this.left,centerP-limit,centerP+limit));
int right = (int)Math.round(clamp(this.right-1,centerP-limit,centerP+limit));
int top = (int)Math.round(clamp(this.top-1,0,255));
int bottom = (int)Math.round(clamp(this.bottom,0,255));
int top = (int)Math.round(clamp(this.top-1, world.min(), world.max()));
int bottom = (int)Math.round(clamp(this.bottom, world.min(), world.max()));

if (left == right) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public boolean contains(BlockPos pos) {
}

@Override
public void iterateClamped(Vec3d center, int limit, Consumer<BlockPos> predicate) {
super.iterateClamped(center, limit, (pos) -> {
public void iterateClamped(Vec3d center, int limit, Util.WorldHeights world, Consumer<BlockPos> predicate) {
super.iterateClamped(center, limit, world, (pos) -> {
if (this.contains(Util.getCenter(pos))) {
predicate.accept(pos);
}
Expand Down

0 comments on commit 5c9364d

Please sign in to comment.