| 1 | package net.minecraft.world.level.border;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.mojang.serialization.Codec;
|
| 5 | import com.mojang.serialization.codecs.RecordCodecBuilder;
|
| 6 | import java.util.List;
|
| 7 | import net.minecraft.core.BlockPos;
|
| 8 | import net.minecraft.resources.Identifier;
|
| 9 | import net.minecraft.util.Mth;
|
| 10 | import net.minecraft.util.datafix.DataFixTypes;
|
| 11 | import net.minecraft.world.entity.Entity;
|
| 12 | import net.minecraft.world.level.ChunkPos;
|
| 13 | import net.minecraft.world.level.saveddata.SavedData;
|
| 14 | import net.minecraft.world.level.saveddata.SavedDataType;
|
| 15 | import net.minecraft.world.phys.AABB;
|
| 16 | import net.minecraft.world.phys.Vec3;
|
| 17 | import net.minecraft.world.phys.shapes.BooleanOp;
|
| 18 | import net.minecraft.world.phys.shapes.Shapes;
|
| 19 | import net.minecraft.world.phys.shapes.VoxelShape;
|
| 20 |
|
| 21 | public class WorldBorder extends SavedData {
|
| 22 | public static final double MAX_SIZE = 5.999997E7F;
|
| 23 | public static final double MAX_CENTER_COORDINATE = 2.9999984E7;
|
| 24 | public static final Codec<WorldBorder> CODEC = WorldBorder.Settings.CODEC.xmap(WorldBorder::new, WorldBorder.Settings::new);
|
| 25 | public static final SavedDataType<WorldBorder> TYPE = new SavedDataType<>(
|
| 26 | Identifier.withDefaultNamespace("world_border"), WorldBorder::new, CODEC, DataFixTypes.SAVED_DATA_WORLD_BORDER
|
| 27 | );
|
| 28 | private final WorldBorder.Settings settings;
|
| 29 | private boolean initialized;
|
| 30 | private final List<BorderChangeListener> listeners = Lists.newArrayList();
|
| 31 | private double damagePerBlock = 0.2;
|
| 32 | private double safeZone = 5.0;
|
| 33 | private int warningTime = 15;
|
| 34 | private int warningBlocks = 5;
|
| 35 | private double centerX;
|
| 36 | private double centerZ;
|
| 37 | private int absoluteMaxSize = 29999984;
|
| 38 | private WorldBorder.BorderExtent extent = new WorldBorder.StaticBorderExtent(5.999997E7F);
|
| 39 |
|
| 40 | public WorldBorder() {
|
| 41 | this(WorldBorder.Settings.DEFAULT);
|
| 42 | }
|
| 43 |
|
| 44 | public WorldBorder(final WorldBorder.Settings settings) {
|
| 45 | this.settings = settings;
|
| 46 | }
|
| 47 |
|
| 48 | public boolean isWithinBounds(final BlockPos pos) {
|
| 49 | return this.isWithinBounds(pos.getX(), pos.getZ());
|
| 50 | }
|
| 51 |
|
| 52 | public boolean isWithinBounds(final Vec3 pos) {
|
| 53 | return this.isWithinBounds(pos.x, pos.z);
|
| 54 | }
|
| 55 |
|
| 56 | public boolean isWithinBounds(final ChunkPos pos) {
|
| 57 | return this.isWithinBounds(pos.getMinBlockX(), pos.getMinBlockZ()) && this.isWithinBounds(pos.getMaxBlockX(), pos.getMaxBlockZ());
|
| 58 | }
|
| 59 |
|
| 60 | public boolean isWithinBounds(final AABB aabb) {
|
| 61 | return this.isWithinBounds(aabb.minX, aabb.minZ, aabb.maxX - 1.0E-5F, aabb.maxZ - 1.0E-5F);
|
| 62 | }
|
| 63 |
|
| 64 | private boolean isWithinBounds(final double minX, final double minZ, final double maxX, final double maxZ) {
|
| 65 | return this.isWithinBounds(minX, minZ) && this.isWithinBounds(maxX, maxZ);
|
| 66 | }
|
| 67 |
|
| 68 | public boolean isWithinBounds(final double x, final double z) {
|
| 69 | return this.isWithinBounds(x, z, 0.0);
|
| 70 | }
|
| 71 |
|
| 72 | public boolean isWithinBounds(final double x, final double z, final double margin) {
|
| 73 | return x >= this.getMinX() - margin && x < this.getMaxX() + margin && z >= this.getMinZ() - margin && z < this.getMaxZ() + margin;
|
| 74 | }
|
| 75 |
|
| 76 | public BlockPos clampToBounds(final BlockPos position) {
|
| 77 | return this.clampToBounds(position.getX(), position.getY(), position.getZ());
|
| 78 | }
|
| 79 |
|
| 80 | public BlockPos clampToBounds(final Vec3 position) {
|
| 81 | return this.clampToBounds(position.x(), position.y(), position.z());
|
| 82 | }
|
| 83 |
|
| 84 | public BlockPos clampToBounds(final double x, final double y, final double z) {
|
| 85 | return BlockPos.containing(this.clampVec3ToBound(x, y, z));
|
| 86 | }
|
| 87 |
|
| 88 | public Vec3 clampVec3ToBound(final Vec3 position) {
|
| 89 | return this.clampVec3ToBound(position.x, position.y, position.z);
|
| 90 | }
|
| 91 |
|
| 92 | public Vec3 clampVec3ToBound(final double x, final double y, final double z) {
|
| 93 | return new Vec3(Mth.clamp(x, this.getMinX(), this.getMaxX() - 1.0E-5F), y, Mth.clamp(z, this.getMinZ(), this.getMaxZ() - 1.0E-5F));
|
| 94 | }
|
| 95 |
|
| 96 | public double getDistanceToBorder(final Entity entity) {
|
| 97 | return this.getDistanceToBorder(entity.getX(), entity.getZ());
|
| 98 | }
|
| 99 |
|
| 100 | public VoxelShape getCollisionShape() {
|
| 101 | return this.extent.getCollisionShape();
|
| 102 | }
|
| 103 |
|
| 104 | public double getDistanceToBorder(final double x, final double z) {
|
| 105 | double fromNorth = z - this.getMinZ();
|
| 106 | double fromSouth = this.getMaxZ() - z;
|
| 107 | double fromWest = x - this.getMinX();
|
| 108 | double fromEast = this.getMaxX() - x;
|
| 109 | double min = Math.min(fromWest, fromEast);
|
| 110 | min = Math.min(min, fromNorth);
|
| 111 | return Math.min(min, fromSouth);
|
| 112 | }
|
| 113 |
|
| 114 | public boolean isInsideCloseToBorder(final Entity source, final AABB boundingBox) {
|
| 115 | double bbMax = Math.max(Mth.absMax(boundingBox.getXsize(), boundingBox.getZsize()), 1.0);
|
| 116 | return this.getDistanceToBorder(source) < bbMax * 2.0 && this.isWithinBounds(source.getX(), source.getZ(), bbMax);
|
| 117 | }
|
| 118 |
|
| 119 | public BorderStatus getStatus() {
|
| 120 | return this.extent.getStatus();
|
| 121 | }
|
| 122 |
|
| 123 | public double getMinX() {
|
| 124 | return this.getMinX(0.0F);
|
| 125 | }
|
| 126 |
|
| 127 | public double getMinX(final float deltaPartialTick) {
|
| 128 | return this.extent.getMinX(deltaPartialTick);
|
| 129 | }
|
| 130 |
|
| 131 | public double getMinZ() {
|
| 132 | return this.getMinZ(0.0F);
|
| 133 | }
|
| 134 |
|
| 135 | public double getMinZ(final float deltaPartialTick) {
|
| 136 | return this.extent.getMinZ(deltaPartialTick);
|
| 137 | }
|
| 138 |
|
| 139 | public double getMaxX() {
|
| 140 | return this.getMaxX(0.0F);
|
| 141 | }
|
| 142 |
|
| 143 | public double getMaxX(final float deltaPartialTick) {
|
| 144 | return this.extent.getMaxX(deltaPartialTick);
|
| 145 | }
|
| 146 |
|
| 147 | public double getMaxZ() {
|
| 148 | return this.getMaxZ(0.0F);
|
| 149 | }
|
| 150 |
|
| 151 | public double getMaxZ(final float deltaPartialTick) {
|
| 152 | return this.extent.getMaxZ(deltaPartialTick);
|
| 153 | }
|
| 154 |
|
| 155 | public double getCenterX() {
|
| 156 | return this.centerX;
|
| 157 | }
|
| 158 |
|
| 159 | public double getCenterZ() {
|
| 160 | return this.centerZ;
|
| 161 | }
|
| 162 |
|
| 163 | public void setCenter(final double x, final double z) {
|
| 164 | this.centerX = x;
|
| 165 | this.centerZ = z;
|
| 166 | this.extent.onCenterChange();
|
| 167 | this.setDirty();
|
| 168 |
|
| 169 | for (BorderChangeListener listener : this.getListeners()) {
|
| 170 | listener.onSetCenter(this, x, z);
|
| 171 | }
|
| 172 | }
|
| 173 |
|
| 174 | public double getSize() {
|
| 175 | return this.extent.getSize();
|
| 176 | }
|
| 177 |
|
| 178 | public long getLerpTime() {
|
| 179 | return this.extent.getLerpTime();
|
| 180 | }
|
| 181 |
|
| 182 | public double getLerpTarget() {
|
| 183 | return this.extent.getLerpTarget();
|
| 184 | }
|
| 185 |
|
| 186 | public void setSize(final double size) {
|
| 187 | this.extent = new WorldBorder.StaticBorderExtent(size);
|
| 188 | this.setDirty();
|
| 189 |
|
| 190 | for (BorderChangeListener listener : this.getListeners()) {
|
| 191 | listener.onSetSize(this, size);
|
| 192 | }
|
| 193 | }
|
| 194 |
|
| 195 | public void lerpSizeBetween(final double from, final double to, final long ticks, final long gameTime) {
|
| 196 | this.extent = from == to ? new WorldBorder.StaticBorderExtent(to) : new WorldBorder.MovingBorderExtent(from, to, ticks, gameTime);
|
| 197 | this.setDirty();
|
| 198 |
|
| 199 | for (BorderChangeListener listener : this.getListeners()) {
|
| 200 | listener.onLerpSize(this, from, to, ticks, gameTime);
|
| 201 | }
|
| 202 | }
|
| 203 |
|
| 204 | protected List<BorderChangeListener> getListeners() {
|
| 205 | return Lists.newArrayList(this.listeners);
|
| 206 | }
|
| 207 |
|
| 208 | public void addListener(final BorderChangeListener listener) {
|
| 209 | this.listeners.add(listener);
|
| 210 | }
|
| 211 |
|
| 212 | public void removeListener(final BorderChangeListener listener) {
|
| 213 | this.listeners.remove(listener);
|
| 214 | }
|
| 215 |
|
| 216 | public void setAbsoluteMaxSize(final int absoluteMaxSize) {
|
| 217 | this.absoluteMaxSize = absoluteMaxSize;
|
| 218 | this.extent.onAbsoluteMaxSizeChange();
|
| 219 | }
|
| 220 |
|
| 221 | public int getAbsoluteMaxSize() {
|
| 222 | return this.absoluteMaxSize;
|
| 223 | }
|
| 224 |
|
| 225 | public double getSafeZone() {
|
| 226 | return this.safeZone;
|
| 227 | }
|
| 228 |
|
| 229 | public void setSafeZone(final double safeZone) {
|
| 230 | this.safeZone = safeZone;
|
| 231 | this.setDirty();
|
| 232 |
|
| 233 | for (BorderChangeListener listener : this.getListeners()) {
|
| 234 | listener.onSetSafeZone(this, safeZone);
|
| 235 | }
|
| 236 | }
|
| 237 |
|
| 238 | public double getDamagePerBlock() {
|
| 239 | return this.damagePerBlock;
|
| 240 | }
|
| 241 |
|
| 242 | public void setDamagePerBlock(final double damagePerBlock) {
|
| 243 | this.damagePerBlock = damagePerBlock;
|
| 244 | this.setDirty();
|
| 245 |
|
| 246 | for (BorderChangeListener listener : this.getListeners()) {
|
| 247 | listener.onSetDamagePerBlock(this, damagePerBlock);
|
| 248 | }
|
| 249 | }
|
| 250 |
|
| 251 | public double getLerpSpeed() {
|
| 252 | return this.extent.getLerpSpeed();
|
| 253 | }
|
| 254 |
|
| 255 | public int getWarningTime() {
|
| 256 | return this.warningTime;
|
| 257 | }
|
| 258 |
|
| 259 | public void setWarningTime(final int warningTime) {
|
| 260 | this.warningTime = warningTime;
|
| 261 | this.setDirty();
|
| 262 |
|
| 263 | for (BorderChangeListener listener : this.getListeners()) {
|
| 264 | listener.onSetWarningTime(this, warningTime);
|
| 265 | }
|
| 266 | }
|
| 267 |
|
| 268 | public int getWarningBlocks() {
|
| 269 | return this.warningBlocks;
|
| 270 | }
|
| 271 |
|
| 272 | public void setWarningBlocks(final int warningBlocks) {
|
| 273 | this.warningBlocks = warningBlocks;
|
| 274 | this.setDirty();
|
| 275 |
|
| 276 | for (BorderChangeListener listener : this.getListeners()) {
|
| 277 | listener.onSetWarningBlocks(this, warningBlocks);
|
| 278 | }
|
| 279 | }
|
| 280 |
|
| 281 | public void tick() {
|
| 282 | this.extent = this.extent.update();
|
| 283 | }
|
| 284 |
|
| 285 | public void applyInitialSettings(final long gameTime) {
|
| 286 | if (!this.initialized) {
|
| 287 | this.setCenter(this.settings.centerX(), this.settings.centerZ());
|
| 288 | this.setDamagePerBlock(this.settings.damagePerBlock());
|
| 289 | this.setSafeZone(this.settings.safeZone());
|
| 290 | this.setWarningBlocks(this.settings.warningBlocks());
|
| 291 | this.setWarningTime(this.settings.warningTime());
|
| 292 | if (this.settings.lerpTime() > 0L) {
|
| 293 | this.lerpSizeBetween(this.settings.size(), this.settings.lerpTarget(), this.settings.lerpTime(), gameTime);
|
| 294 | } else {
|
| 295 | this.setSize(this.settings.size());
|
| 296 | }
|
| 297 |
|
| 298 | this.initialized = true;
|
| 299 | }
|
| 300 | }
|
| 301 |
|
| 302 | private interface BorderExtent {
|
| 303 | double getMinX(final float deltaPartialTick);
|
| 304 |
|
| 305 | double getMaxX(final float deltaPartialTick);
|
| 306 |
|
| 307 | double getMinZ(final float deltaPartialTick);
|
| 308 |
|
| 309 | double getMaxZ(final float deltaPartialTick);
|
| 310 |
|
| 311 | double getSize();
|
| 312 |
|
| 313 | double getLerpSpeed();
|
| 314 |
|
| 315 | long getLerpTime();
|
| 316 |
|
| 317 | double getLerpTarget();
|
| 318 |
|
| 319 | BorderStatus getStatus();
|
| 320 |
|
| 321 | void onAbsoluteMaxSizeChange();
|
| 322 |
|
| 323 | void onCenterChange();
|
| 324 |
|
| 325 | WorldBorder.BorderExtent update();
|
| 326 |
|
| 327 | VoxelShape getCollisionShape();
|
| 328 | }
|
| 329 |
|
| 330 | private class MovingBorderExtent implements WorldBorder.BorderExtent {
|
| 331 | private final double from;
|
| 332 | private final double to;
|
| 333 | private final long lerpEnd;
|
| 334 | private final long lerpBegin;
|
| 335 | private final double lerpDuration;
|
| 336 | private long lerpProgress;
|
| 337 | private double size;
|
| 338 | private double previousSize;
|
| 339 |
|
| 340 | private MovingBorderExtent(final double from, final double to, final long duration, final long gameTime) {
|
| 341 | this.from = from;
|
| 342 | this.to = to;
|
| 343 | this.lerpDuration = duration;
|
| 344 | this.lerpProgress = duration;
|
| 345 | this.lerpBegin = gameTime;
|
| 346 | this.lerpEnd = this.lerpBegin + duration;
|
| 347 | double size = this.calculateSize();
|
| 348 | this.size = size;
|
| 349 | this.previousSize = size;
|
| 350 | }
|
| 351 |
|
| 352 | @Override
|
| 353 | public double getMinX(final float deltaPartialTick) {
|
| 354 | return Mth.clamp(
|
| 355 | WorldBorder.this.getCenterX() - Mth.lerp(deltaPartialTick, this.getPreviousSize(), this.getSize()) / 2.0,
|
| 356 | -WorldBorder.this.absoluteMaxSize,
|
| 357 | WorldBorder.this.absoluteMaxSize
|
| 358 | );
|
| 359 | }
|
| 360 |
|
| 361 | @Override
|
| 362 | public double getMinZ(final float deltaPartialTick) {
|
| 363 | return Mth.clamp(
|
| 364 | WorldBorder.this.getCenterZ() - Mth.lerp(deltaPartialTick, this.getPreviousSize(), this.getSize()) / 2.0,
|
| 365 | -WorldBorder.this.absoluteMaxSize,
|
| 366 | WorldBorder.this.absoluteMaxSize
|
| 367 | );
|
| 368 | }
|
| 369 |
|
| 370 | @Override
|
| 371 | public double getMaxX(final float deltaPartialTick) {
|
| 372 | return Mth.clamp(
|
| 373 | WorldBorder.this.getCenterX() + Mth.lerp(deltaPartialTick, this.getPreviousSize(), this.getSize()) / 2.0,
|
| 374 | -WorldBorder.this.absoluteMaxSize,
|
| 375 | WorldBorder.this.absoluteMaxSize
|
| 376 | );
|
| 377 | }
|
| 378 |
|
| 379 | @Override
|
| 380 | public double getMaxZ(final float deltaPartialTick) {
|
| 381 | return Mth.clamp(
|
| 382 | WorldBorder.this.getCenterZ() + Mth.lerp(deltaPartialTick, this.getPreviousSize(), this.getSize()) / 2.0,
|
| 383 | -WorldBorder.this.absoluteMaxSize,
|
| 384 | WorldBorder.this.absoluteMaxSize
|
| 385 | );
|
| 386 | }
|
| 387 |
|
| 388 | @Override
|
| 389 | public double getSize() {
|
| 390 | return this.size;
|
| 391 | }
|
| 392 |
|
| 393 | public double getPreviousSize() {
|
| 394 | return this.previousSize;
|
| 395 | }
|
| 396 |
|
| 397 | private double calculateSize() {
|
| 398 | double progress = (this.lerpDuration - this.lerpProgress) / this.lerpDuration;
|
| 399 | return progress < 1.0 ? Mth.lerp(progress, this.from, this.to) : this.to;
|
| 400 | }
|
| 401 |
|
| 402 | @Override
|
| 403 | public double getLerpSpeed() {
|
| 404 | return Math.abs(this.from - this.to) / (this.lerpEnd - this.lerpBegin);
|
| 405 | }
|
| 406 |
|
| 407 | @Override
|
| 408 | public long getLerpTime() {
|
| 409 | return this.lerpProgress;
|
| 410 | }
|
| 411 |
|
| 412 | @Override
|
| 413 | public double getLerpTarget() {
|
| 414 | return this.to;
|
| 415 | }
|
| 416 |
|
| 417 | @Override
|
| 418 | public BorderStatus getStatus() {
|
| 419 | return this.to < this.from ? BorderStatus.SHRINKING : BorderStatus.GROWING;
|
| 420 | }
|
| 421 |
|
| 422 | @Override
|
| 423 | public void onCenterChange() {
|
| 424 | }
|
| 425 |
|
| 426 | @Override
|
| 427 | public void onAbsoluteMaxSizeChange() {
|
| 428 | }
|
| 429 |
|
| 430 | @Override
|
| 431 | public WorldBorder.BorderExtent update() {
|
| 432 | this.lerpProgress--;
|
| 433 | this.previousSize = this.size;
|
| 434 | this.size = this.calculateSize();
|
| 435 | WorldBorder.this.setDirty();
|
| 436 | return this.lerpProgress <= 0L ? WorldBorder.this.new StaticBorderExtent(this.to) : this;
|
| 437 | }
|
| 438 |
|
| 439 | @Override
|
| 440 | public VoxelShape getCollisionShape() {
|
| 441 | return Shapes.join(
|
| 442 | Shapes.INFINITY,
|
| 443 | Shapes.box(
|
| 444 | Math.floor(this.getMinX(0.0F)),
|
| 445 | Double.NEGATIVE_INFINITY,
|
| 446 | Math.floor(this.getMinZ(0.0F)),
|
| 447 | Math.ceil(this.getMaxX(0.0F)),
|
| 448 | Double.POSITIVE_INFINITY,
|
| 449 | Math.ceil(this.getMaxZ(0.0F))
|
| 450 | ),
|
| 451 | BooleanOp.ONLY_FIRST
|
| 452 | );
|
| 453 | }
|
| 454 | }
|
| 455 |
|
| 456 | public record Settings(
|
| 457 | double centerX, double centerZ, double damagePerBlock, double safeZone, int warningBlocks, int warningTime, double size, long lerpTime, double lerpTarget
|
| 458 | ) {
|
| 459 | public static final WorldBorder.Settings DEFAULT = new WorldBorder.Settings(0.0, 0.0, 0.2, 5.0, 5, 300, 5.999997E7F, 0L, 0.0);
|
| 460 | public static final Codec<WorldBorder.Settings> CODEC = RecordCodecBuilder.create(
|
| 461 | i -> i.group(
|
| 462 | Codec.doubleRange(-2.9999984E7, 2.9999984E7).fieldOf("center_x").forGetter(WorldBorder.Settings::centerX),
|
| 463 | Codec.doubleRange(-2.9999984E7, 2.9999984E7).fieldOf("center_z").forGetter(WorldBorder.Settings::centerZ),
|
| 464 | Codec.DOUBLE.fieldOf("damage_per_block").forGetter(WorldBorder.Settings::damagePerBlock),
|
| 465 | Codec.DOUBLE.fieldOf("safe_zone").forGetter(WorldBorder.Settings::safeZone),
|
| 466 | Codec.INT.fieldOf("warning_blocks").forGetter(WorldBorder.Settings::warningBlocks),
|
| 467 | Codec.INT.fieldOf("warning_time").forGetter(WorldBorder.Settings::warningTime),
|
| 468 | Codec.DOUBLE.fieldOf("size").forGetter(WorldBorder.Settings::size),
|
| 469 | Codec.LONG.fieldOf("lerp_time").forGetter(WorldBorder.Settings::lerpTime),
|
| 470 | Codec.DOUBLE.fieldOf("lerp_target").forGetter(WorldBorder.Settings::lerpTarget)
|
| 471 | )
|
| 472 | .apply(i, WorldBorder.Settings::new)
|
| 473 | );
|
| 474 |
|
| 475 | public Settings(final WorldBorder worldBorder) {
|
| 476 | this(
|
| 477 | worldBorder.centerX,
|
| 478 | worldBorder.centerZ,
|
| 479 | worldBorder.damagePerBlock,
|
| 480 | worldBorder.safeZone,
|
| 481 | worldBorder.warningBlocks,
|
| 482 | worldBorder.warningTime,
|
| 483 | worldBorder.extent.getSize(),
|
| 484 | worldBorder.extent.getLerpTime(),
|
| 485 | worldBorder.extent.getLerpTarget()
|
| 486 | );
|
| 487 | }
|
| 488 | }
|
| 489 |
|
| 490 | private class StaticBorderExtent implements WorldBorder.BorderExtent {
|
| 491 | private final double size;
|
| 492 | private double minX;
|
| 493 | private double minZ;
|
| 494 | private double maxX;
|
| 495 | private double maxZ;
|
| 496 | private VoxelShape shape;
|
| 497 |
|
| 498 | public StaticBorderExtent(final double size) {
|
| 499 | this.size = size;
|
| 500 | this.updateBox();
|
| 501 | }
|
| 502 |
|
| 503 | @Override
|
| 504 | public double getMinX(final float deltaPartialTick) {
|
| 505 | return this.minX;
|
| 506 | }
|
| 507 |
|
| 508 | @Override
|
| 509 | public double getMaxX(final float deltaPartialTick) {
|
| 510 | return this.maxX;
|
| 511 | }
|
| 512 |
|
| 513 | @Override
|
| 514 | public double getMinZ(final float deltaPartialTick) {
|
| 515 | return this.minZ;
|
| 516 | }
|
| 517 |
|
| 518 | @Override
|
| 519 | public double getMaxZ(final float deltaPartialTick) {
|
| 520 | return this.maxZ;
|
| 521 | }
|
| 522 |
|
| 523 | @Override
|
| 524 | public double getSize() {
|
| 525 | return this.size;
|
| 526 | }
|
| 527 |
|
| 528 | @Override
|
| 529 | public BorderStatus getStatus() {
|
| 530 | return BorderStatus.STATIONARY;
|
| 531 | }
|
| 532 |
|
| 533 | @Override
|
| 534 | public double getLerpSpeed() {
|
| 535 | return 0.0;
|
| 536 | }
|
| 537 |
|
| 538 | @Override
|
| 539 | public long getLerpTime() {
|
| 540 | return 0L;
|
| 541 | }
|
| 542 |
|
| 543 | @Override
|
| 544 | public double getLerpTarget() {
|
| 545 | return this.size;
|
| 546 | }
|
| 547 |
|
| 548 | private void updateBox() {
|
| 549 | this.minX = Mth.clamp(WorldBorder.this.getCenterX() - this.size / 2.0, -WorldBorder.this.absoluteMaxSize, WorldBorder.this.absoluteMaxSize);
|
| 550 | this.minZ = Mth.clamp(WorldBorder.this.getCenterZ() - this.size / 2.0, -WorldBorder.this.absoluteMaxSize, WorldBorder.this.absoluteMaxSize);
|
| 551 | this.maxX = Mth.clamp(WorldBorder.this.getCenterX() + this.size / 2.0, -WorldBorder.this.absoluteMaxSize, WorldBorder.this.absoluteMaxSize);
|
| 552 | this.maxZ = Mth.clamp(WorldBorder.this.getCenterZ() + this.size / 2.0, -WorldBorder.this.absoluteMaxSize, WorldBorder.this.absoluteMaxSize);
|
| 553 | this.shape = Shapes.join(
|
| 554 | Shapes.INFINITY,
|
| 555 | Shapes.box(
|
| 556 | Math.floor(this.getMinX(0.0F)),
|
| 557 | Double.NEGATIVE_INFINITY,
|
| 558 | Math.floor(this.getMinZ(0.0F)),
|
| 559 | Math.ceil(this.getMaxX(0.0F)),
|
| 560 | Double.POSITIVE_INFINITY,
|
| 561 | Math.ceil(this.getMaxZ(0.0F))
|
| 562 | ),
|
| 563 | BooleanOp.ONLY_FIRST
|
| 564 | );
|
| 565 | }
|
| 566 |
|
| 567 | @Override
|
| 568 | public void onAbsoluteMaxSizeChange() {
|
| 569 | this.updateBox();
|
| 570 | }
|
| 571 |
|
| 572 | @Override
|
| 573 | public void onCenterChange() {
|
| 574 | this.updateBox();
|
| 575 | }
|
| 576 |
|
| 577 | @Override
|
| 578 | public WorldBorder.BorderExtent update() {
|
| 579 | return this;
|
| 580 | }
|
| 581 |
|
| 582 | @Override
|
| 583 | public VoxelShape getCollisionShape() {
|
| 584 | return this.shape;
|
| 585 | }
|
| 586 | }
|
| 587 | }
|
| 588 |
|