| 1 | package net.minecraft.world.level;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import com.mojang.serialization.Codec;
|
| 5 | import java.io.IOException;
|
| 6 | import java.util.Collection;
|
| 7 | import java.util.Iterator;
|
| 8 | import java.util.List;
|
| 9 | import java.util.Locale;
|
| 10 | import java.util.Optional;
|
| 11 | import java.util.UUID;
|
| 12 | import java.util.function.Consumer;
|
| 13 | import java.util.function.Predicate;
|
| 14 | import java.util.stream.Collectors;
|
| 15 | import net.fabricmc.fabric.api.attachment.v1.AttachmentTarget;
|
| 16 | import net.fabricmc.fabric.api.attachment.v1.GlobalAttachmentsProvider;
|
| 17 | import net.minecraft.CrashReport;
|
| 18 | import net.minecraft.CrashReportCategory;
|
| 19 | import net.minecraft.ReportedException;
|
| 20 | import net.minecraft.core.BlockPos;
|
| 21 | import net.minecraft.core.Direction;
|
| 22 | import net.minecraft.core.Holder;
|
| 23 | import net.minecraft.core.RegistryAccess;
|
| 24 | import net.minecraft.core.SectionPos;
|
| 25 | import net.minecraft.core.particles.ExplosionParticleInfo;
|
| 26 | import net.minecraft.core.particles.ParticleOptions;
|
| 27 | import net.minecraft.core.particles.ParticleTypes;
|
| 28 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 29 | import net.minecraft.core.registries.Registries;
|
| 30 | import net.minecraft.network.protocol.Packet;
|
| 31 | import net.minecraft.resources.Identifier;
|
| 32 | import net.minecraft.resources.ResourceKey;
|
| 33 | import net.minecraft.server.MinecraftServer;
|
| 34 | import net.minecraft.server.level.FullChunkStatus;
|
| 35 | import net.minecraft.sounds.SoundEvent;
|
| 36 | import net.minecraft.sounds.SoundEvents;
|
| 37 | import net.minecraft.sounds.SoundSource;
|
| 38 | import net.minecraft.util.Continuation;
|
| 39 | import net.minecraft.util.Mth;
|
| 40 | import net.minecraft.util.RandomSource;
|
| 41 | import net.minecraft.util.StringRepresentable;
|
| 42 | import net.minecraft.util.profiling.Profiler;
|
| 43 | import net.minecraft.util.random.WeightedList;
|
| 44 | import net.minecraft.world.TickRateManager;
|
| 45 | import net.minecraft.world.attribute.EnvironmentAttributeSystem;
|
| 46 | import net.minecraft.world.attribute.EnvironmentAttributes;
|
| 47 | import net.minecraft.world.clock.ClockManager;
|
| 48 | import net.minecraft.world.clock.WorldClock;
|
| 49 | import net.minecraft.world.clock.WorldClocks;
|
| 50 | import net.minecraft.world.damagesource.DamageSource;
|
| 51 | import net.minecraft.world.damagesource.DamageSources;
|
| 52 | import net.minecraft.world.entity.Entity;
|
| 53 | import net.minecraft.world.entity.EntityEvent;
|
| 54 | import net.minecraft.world.entity.EntitySelector;
|
| 55 | import net.minecraft.world.entity.boss.enderdragon.EnderDragon;
|
| 56 | import net.minecraft.world.entity.boss.enderdragon.EnderDragonPart;
|
| 57 | import net.minecraft.world.entity.player.Player;
|
| 58 | import net.minecraft.world.item.ItemStack;
|
| 59 | import net.minecraft.world.item.component.FireworkExplosion;
|
| 60 | import net.minecraft.world.item.crafting.RecipeAccess;
|
| 61 | import net.minecraft.world.level.biome.Biome;
|
| 62 | import net.minecraft.world.level.biome.BiomeManager;
|
| 63 | import net.minecraft.world.level.block.Block;
|
| 64 | import net.minecraft.world.level.block.Blocks;
|
| 65 | import net.minecraft.world.level.block.LevelEvent;
|
| 66 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 67 | import net.minecraft.world.level.block.entity.TickingBlockEntity;
|
| 68 | import net.minecraft.world.level.block.state.BlockState;
|
| 69 | import net.minecraft.world.level.border.WorldBorder;
|
| 70 | import net.minecraft.world.level.chunk.ChunkAccess;
|
| 71 | import net.minecraft.world.level.chunk.LevelChunk;
|
| 72 | import net.minecraft.world.level.chunk.PalettedContainerFactory;
|
| 73 | import net.minecraft.world.level.chunk.status.ChunkStatus;
|
| 74 | import net.minecraft.world.level.dimension.DimensionType;
|
| 75 | import net.minecraft.world.level.entity.EntityTypeTest;
|
| 76 | import net.minecraft.world.level.entity.LevelEntityGetter;
|
| 77 | import net.minecraft.world.level.gameevent.GameEvent;
|
| 78 | import net.minecraft.world.level.levelgen.Heightmap;
|
| 79 | import net.minecraft.world.level.lighting.LevelLightEngine;
|
| 80 | import net.minecraft.world.level.material.FluidState;
|
| 81 | import net.minecraft.world.level.material.Fluids;
|
| 82 | import net.minecraft.world.level.redstone.CollectingNeighborUpdater;
|
| 83 | import net.minecraft.world.level.redstone.Orientation;
|
| 84 | import net.minecraft.world.level.saveddata.maps.MapId;
|
| 85 | import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
| 86 | import net.minecraft.world.level.storage.LevelData;
|
| 87 | import net.minecraft.world.level.storage.WritableLevelData;
|
| 88 | import net.minecraft.world.phys.AABB;
|
| 89 | import net.minecraft.world.phys.Vec3;
|
| 90 | import net.minecraft.world.scores.Scoreboard;
|
| 91 | import org.apache.commons.lang3.mutable.MutableBoolean;
|
| 92 | import org.jspecify.annotations.Nullable;
|
| 93 |
|
| 94 | public abstract class Level implements LevelAccessor, AutoCloseable, AttachmentTarget, GlobalAttachmentsProvider {
|
| 95 | public static final Codec<ResourceKey<Level>> RESOURCE_KEY_CODEC = ResourceKey.codec(Registries.DIMENSION);
|
| 96 | public static final ResourceKey<Level> OVERWORLD = ResourceKey.create(Registries.DIMENSION, Identifier.withDefaultNamespace("overworld"));
|
| 97 | public static final ResourceKey<Level> NETHER = ResourceKey.create(Registries.DIMENSION, Identifier.withDefaultNamespace("the_nether"));
|
| 98 | public static final ResourceKey<Level> END = ResourceKey.create(Registries.DIMENSION, Identifier.withDefaultNamespace("the_end"));
|
| 99 | public static final int MAX_LEVEL_SIZE = 30000000;
|
| 100 | public static final int ACROSS_THE_WHOLE_WORLD = 60000000;
|
| 101 | public static final int LONG_PARTICLE_CLIP_RANGE = 512;
|
| 102 | public static final int SHORT_PARTICLE_CLIP_RANGE = 32;
|
| 103 | public static final int MAX_BRIGHTNESS = 15;
|
| 104 | public static final int MAX_ENTITY_SPAWN_Y = 20000000;
|
| 105 | public static final int MIN_ENTITY_SPAWN_Y = -20000000;
|
| 106 | private static final WeightedList<ExplosionParticleInfo> DEFAULT_EXPLOSION_BLOCK_PARTICLES = WeightedList.<ExplosionParticleInfo>builder()
|
| 107 | .add(new ExplosionParticleInfo(ParticleTypes.POOF, 0.5F, 1.0F))
|
| 108 | .add(new ExplosionParticleInfo(ParticleTypes.SMOKE, 1.0F, 1.0F))
|
| 109 | .build();
|
| 110 | protected final List<TickingBlockEntity> blockEntityTickers = Lists.newArrayList();
|
| 111 | protected final CollectingNeighborUpdater neighborUpdater;
|
| 112 | private final List<TickingBlockEntity> pendingBlockEntityTickers = Lists.newArrayList();
|
| 113 | private boolean tickingBlockEntities;
|
| 114 | private final Thread thread;
|
| 115 | private final boolean isDebug;
|
| 116 | private int skyDarken;
|
| 117 | protected int randValue = RandomSource.createThreadLocalInstance().nextInt();
|
| 118 | protected final int addend = 1013904223;
|
| 119 | protected float oRainLevel;
|
| 120 | protected float rainLevel;
|
| 121 | protected float oThunderLevel;
|
| 122 | protected float thunderLevel;
|
| 123 | protected final RandomSource random = RandomSource.create();
|
| 124 | @Deprecated
|
| 125 | private final RandomSource soundSeedGenerator = RandomSource.createThreadSafe();
|
| 126 | private final Holder<DimensionType> dimensionTypeRegistration;
|
| 127 | protected final WritableLevelData levelData;
|
| 128 | private final boolean isClientSide;
|
| 129 | private final BiomeManager biomeManager;
|
| 130 | private final ResourceKey<Level> dimension;
|
| 131 | private final RegistryAccess registryAccess;
|
| 132 | private final DamageSources damageSources;
|
| 133 | private final PalettedContainerFactory palettedContainerFactory;
|
| 134 | private long subTickCount;
|
| 135 |
|
| 136 | protected Level(
|
| 137 | final WritableLevelData levelData,
|
| 138 | final ResourceKey<Level> dimension,
|
| 139 | final RegistryAccess registryAccess,
|
| 140 | final Holder<DimensionType> dimensionTypeRegistration,
|
| 141 | final boolean isClientSide,
|
| 142 | final boolean isDebug,
|
| 143 | final long biomeZoomSeed,
|
| 144 | final int maxChainedNeighborUpdates
|
| 145 | ) {
|
| 146 | this.levelData = levelData;
|
| 147 | this.dimensionTypeRegistration = dimensionTypeRegistration;
|
| 148 | this.dimension = dimension;
|
| 149 | this.isClientSide = isClientSide;
|
| 150 | this.thread = Thread.currentThread();
|
| 151 | this.biomeManager = new BiomeManager(this, biomeZoomSeed);
|
| 152 | this.isDebug = isDebug;
|
| 153 | this.neighborUpdater = new CollectingNeighborUpdater(this, maxChainedNeighborUpdates);
|
| 154 | this.registryAccess = registryAccess;
|
| 155 | this.palettedContainerFactory = PalettedContainerFactory.create(registryAccess);
|
| 156 | this.damageSources = new DamageSources(registryAccess);
|
| 157 | }
|
| 158 |
|
| 159 | public int getNextEntityId() {
|
| 160 | return 0;
|
| 161 | }
|
| 162 |
|
| 163 | @Override
|
| 164 | public boolean isClientSide() {
|
| 165 | return this.isClientSide;
|
| 166 | }
|
| 167 |
|
| 168 | @Override
|
| 169 | public @Nullable MinecraftServer getServer() {
|
| 170 | return null;
|
| 171 | }
|
| 172 |
|
| 173 | public boolean isInWorldBounds(final BlockPos pos) {
|
| 174 | return this.isInsideBuildHeight(pos) && isInWorldBoundsHorizontal(pos);
|
| 175 | }
|
| 176 |
|
| 177 | public boolean isInValidBounds(final BlockPos pos) {
|
| 178 | return this.isInsideBuildHeight(pos) && isInValidBoundsHorizontal(pos);
|
| 179 | }
|
| 180 |
|
| 181 | public static boolean isInSpawnableBounds(final BlockPos pos) {
|
| 182 | return !isOutsideSpawnableHeight(pos.getY()) && isInWorldBoundsHorizontal(pos);
|
| 183 | }
|
| 184 |
|
| 185 | private static boolean isInWorldBoundsHorizontal(final BlockPos pos) {
|
| 186 | return pos.getX() >= -30000000 && pos.getZ() >= -30000000 && pos.getX() < 30000000 && pos.getZ() < 30000000;
|
| 187 | }
|
| 188 |
|
| 189 | private static boolean isInValidBoundsHorizontal(final BlockPos pos) {
|
| 190 | int chunkX = SectionPos.blockToSectionCoord(pos.getX());
|
| 191 | int chunkZ = SectionPos.blockToSectionCoord(pos.getZ());
|
| 192 | return ChunkPos.isValid(chunkX, chunkZ);
|
| 193 | }
|
| 194 |
|
| 195 | private static boolean isOutsideSpawnableHeight(final int y) {
|
| 196 | return y < -20000000 || y >= 20000000;
|
| 197 | }
|
| 198 |
|
| 199 | public LevelChunk getChunkAt(final BlockPos pos) {
|
| 200 | return this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()));
|
| 201 | }
|
| 202 |
|
| 203 | public LevelChunk getChunk(final int chunkX, final int chunkZ) {
|
| 204 | return (LevelChunk)this.getChunk(chunkX, chunkZ, ChunkStatus.FULL);
|
| 205 | }
|
| 206 |
|
| 207 | @Override
|
| 208 | public @Nullable ChunkAccess getChunk(final int chunkX, final int chunkZ, final ChunkStatus status, final boolean loadOrGenerate) {
|
| 209 | ChunkAccess chunk = this.getChunkSource().getChunk(chunkX, chunkZ, status, loadOrGenerate);
|
| 210 | if (chunk == null && loadOrGenerate) {
|
| 211 | throw new IllegalStateException("Should always be able to create a chunk!");
|
| 212 | } else {
|
| 213 | return chunk;
|
| 214 | }
|
| 215 | }
|
| 216 |
|
| 217 | @Override
|
| 218 | public boolean setBlock(final BlockPos pos, final BlockState blockState, final @Block.UpdateFlags int updateFlags, final int updateLimit) {
|
| 219 | if (!this.isInValidBounds(pos)) {
|
| 220 | return false;
|
| 221 | }
|
| 222 |
|
| 223 | if (!this.isClientSide() && this.isDebug()) {
|
| 224 | return false;
|
| 225 | }
|
| 226 |
|
| 227 | LevelChunk chunk = this.getChunkAt(pos);
|
| 228 | Block block = blockState.getBlock();
|
| 229 | BlockState oldState = chunk.setBlockState(pos, blockState, updateFlags);
|
| 230 | if (oldState == null) {
|
| 231 | return false;
|
| 232 | }
|
| 233 |
|
| 234 | BlockState newState = this.getBlockState(pos);
|
| 235 | if (newState == blockState) {
|
| 236 | if (oldState != newState) {
|
| 237 | this.setBlocksDirty(pos, oldState, newState);
|
| 238 | }
|
| 239 |
|
| 240 | if ((updateFlags & 2) != 0
|
| 241 | && (!this.isClientSide() || (updateFlags & 4) == 0)
|
| 242 | && (this.isClientSide() || chunk.getFullStatus() != null && chunk.getFullStatus().isOrAfter(FullChunkStatus.BLOCK_TICKING))) {
|
| 243 | this.sendBlockUpdated(pos, oldState, blockState, updateFlags);
|
| 244 | }
|
| 245 |
|
| 246 | if ((updateFlags & 1) != 0) {
|
| 247 | this.updateNeighborsAt(pos, oldState.getBlock());
|
| 248 | if (!this.isClientSide() && blockState.hasAnalogOutputSignal()) {
|
| 249 | this.updateNeighbourForOutputSignal(pos, block);
|
| 250 | }
|
| 251 | }
|
| 252 |
|
| 253 | if ((updateFlags & 16) == 0 && updateLimit > 0) {
|
| 254 | int neighbourUpdateFlags = updateFlags & -34;
|
| 255 | oldState.updateIndirectNeighbourShapes(this, pos, neighbourUpdateFlags, updateLimit - 1);
|
| 256 | blockState.updateNeighbourShapes(this, pos, neighbourUpdateFlags, updateLimit - 1);
|
| 257 | blockState.updateIndirectNeighbourShapes(this, pos, neighbourUpdateFlags, updateLimit - 1);
|
| 258 | }
|
| 259 |
|
| 260 | this.updatePOIOnBlockStateChange(pos, oldState, newState);
|
| 261 | }
|
| 262 |
|
| 263 | return true;
|
| 264 | }
|
| 265 |
|
| 266 | public void updatePOIOnBlockStateChange(final BlockPos pos, final BlockState oldState, final BlockState newState) {
|
| 267 | }
|
| 268 |
|
| 269 | @Override
|
| 270 | public boolean removeBlock(final BlockPos pos, final boolean movedByPiston) {
|
| 271 | FluidState fluidState = this.getFluidState(pos);
|
| 272 | return this.setBlock(pos, fluidState.createLegacyBlock(), 3 | (movedByPiston ? 64 : 0));
|
| 273 | }
|
| 274 |
|
| 275 | @Override
|
| 276 | public boolean destroyBlock(final BlockPos pos, final boolean dropResources, final @Nullable Entity breaker, final int updateLimit) {
|
| 277 | BlockState blockState = this.getBlockState(pos);
|
| 278 | if (blockState.isAir()) {
|
| 279 | return false;
|
| 280 | }
|
| 281 |
|
| 282 | blockState.getBlock().spawnDestroyParticles(this, pos, blockState);
|
| 283 | if (dropResources) {
|
| 284 | BlockEntity blockEntity = blockState.hasBlockEntity() ? this.getBlockEntity(pos) : null;
|
| 285 | Block.dropResources(blockState, this, pos, blockEntity, breaker, ItemStack.EMPTY);
|
| 286 | }
|
| 287 |
|
| 288 | FluidState fluidState = this.getFluidState(pos);
|
| 289 | boolean destroyed = this.setBlock(pos, fluidState.createLegacyBlock(), 3, updateLimit);
|
| 290 | if (destroyed) {
|
| 291 | this.gameEvent(GameEvent.BLOCK_DESTROY, pos, GameEvent.Context.of(breaker, blockState));
|
| 292 | }
|
| 293 |
|
| 294 | return destroyed;
|
| 295 | }
|
| 296 |
|
| 297 | public void addDestroyBlockEffect(final BlockPos pos, final BlockState blockState) {
|
| 298 | }
|
| 299 |
|
| 300 | public abstract void sendBlockUpdated(BlockPos pos, BlockState old, BlockState current, @Block.UpdateFlags int updateFlags);
|
| 301 |
|
| 302 | public void setBlocksDirty(final BlockPos pos, final BlockState oldState, final BlockState newState) {
|
| 303 | }
|
| 304 |
|
| 305 | public void updateNeighborsAt(final BlockPos pos, final Block sourceBlock, final @Nullable Orientation orientation) {
|
| 306 | }
|
| 307 |
|
| 308 | public void updateNeighborsAtExceptFromFacing(
|
| 309 | final BlockPos pos, final Block blockObject, final Direction skipDirection, final @Nullable Orientation orientation
|
| 310 | ) {
|
| 311 | }
|
| 312 |
|
| 313 | public void neighborChanged(final BlockPos pos, final Block changedBlock, final @Nullable Orientation orientation) {
|
| 314 | }
|
| 315 |
|
| 316 | public void neighborChanged(
|
| 317 | final BlockState state, final BlockPos pos, final Block changedBlock, final @Nullable Orientation orientation, final boolean movedByPiston
|
| 318 | ) {
|
| 319 | }
|
| 320 |
|
| 321 | @Override
|
| 322 | public void neighborShapeChanged(
|
| 323 | final Direction direction,
|
| 324 | final BlockPos pos,
|
| 325 | final BlockPos neighborPos,
|
| 326 | final BlockState neighborState,
|
| 327 | final @Block.UpdateFlags int updateFlags,
|
| 328 | final int updateLimit
|
| 329 | ) {
|
| 330 | this.neighborUpdater.shapeUpdate(direction, neighborState, pos, neighborPos, updateFlags, updateLimit);
|
| 331 | }
|
| 332 |
|
| 333 | @Override
|
| 334 | public int getHeight(final Heightmap.Types type, final int x, final int z) {
|
| 335 | int y;
|
| 336 | if (x >= -30000000 && z >= -30000000 && x < 30000000 && z < 30000000) {
|
| 337 | if (this.hasChunk(SectionPos.blockToSectionCoord(x), SectionPos.blockToSectionCoord(z))) {
|
| 338 | y = this.getChunk(SectionPos.blockToSectionCoord(x), SectionPos.blockToSectionCoord(z)).getHeight(type, x & 15, z & 15) + 1;
|
| 339 | } else {
|
| 340 | y = this.getMinY();
|
| 341 | }
|
| 342 | } else {
|
| 343 | y = this.getSeaLevel() + 1;
|
| 344 | }
|
| 345 |
|
| 346 | return y;
|
| 347 | }
|
| 348 |
|
| 349 | @Override
|
| 350 | public LevelLightEngine getLightEngine() {
|
| 351 | return this.getChunkSource().getLightEngine();
|
| 352 | }
|
| 353 |
|
| 354 | @Override
|
| 355 | public BlockState getBlockState(final BlockPos pos) {
|
| 356 | if (!this.isInValidBounds(pos)) {
|
| 357 | return Blocks.VOID_AIR.defaultBlockState();
|
| 358 | }
|
| 359 |
|
| 360 | LevelChunk chunk = this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()));
|
| 361 | return chunk.getBlockState(pos);
|
| 362 | }
|
| 363 |
|
| 364 | @Override
|
| 365 | public FluidState getFluidState(final BlockPos pos) {
|
| 366 | if (!this.isInValidBounds(pos)) {
|
| 367 | return Fluids.EMPTY.defaultFluidState();
|
| 368 | }
|
| 369 |
|
| 370 | LevelChunk chunk = this.getChunkAt(pos);
|
| 371 | return chunk.getFluidState(pos);
|
| 372 | }
|
| 373 |
|
| 374 | public boolean isBrightOutside() {
|
| 375 | return !this.dimensionType().hasFixedTime() && this.skyDarken < 4;
|
| 376 | }
|
| 377 |
|
| 378 | public boolean isDarkOutside() {
|
| 379 | return !this.dimensionType().hasFixedTime() && !this.isBrightOutside();
|
| 380 | }
|
| 381 |
|
| 382 | @Override
|
| 383 | public void playSound(
|
| 384 | final @Nullable Entity except, final BlockPos pos, final SoundEvent sound, final SoundSource source, final float volume, final float pitch
|
| 385 | ) {
|
| 386 | this.playSound(except, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, sound, source, volume, pitch);
|
| 387 | }
|
| 388 |
|
| 389 | public abstract void playSeededSound(
|
| 390 | final @Nullable Entity except,
|
| 391 | final double x,
|
| 392 | final double y,
|
| 393 | final double z,
|
| 394 | final Holder<SoundEvent> sound,
|
| 395 | final SoundSource source,
|
| 396 | final float volume,
|
| 397 | final float pitch,
|
| 398 | final long seed
|
| 399 | );
|
| 400 |
|
| 401 | public void playSeededSound(
|
| 402 | final @Nullable Entity except,
|
| 403 | final double x,
|
| 404 | final double y,
|
| 405 | final double z,
|
| 406 | final SoundEvent sound,
|
| 407 | final SoundSource source,
|
| 408 | final float volume,
|
| 409 | final float pitch,
|
| 410 | final long seed
|
| 411 | ) {
|
| 412 | this.playSeededSound(except, x, y, z, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), source, volume, pitch, seed);
|
| 413 | }
|
| 414 |
|
| 415 | public abstract void playSeededSound(
|
| 416 | final @Nullable Entity except,
|
| 417 | final Entity sourceEntity,
|
| 418 | final Holder<SoundEvent> sound,
|
| 419 | final SoundSource source,
|
| 420 | final float volume,
|
| 421 | final float pitch,
|
| 422 | final long seed
|
| 423 | );
|
| 424 |
|
| 425 | public void playSound(final @Nullable Entity except, final double x, final double y, final double z, final SoundEvent sound, final SoundSource source) {
|
| 426 | this.playSound(except, x, y, z, sound, source, 1.0F, 1.0F);
|
| 427 | }
|
| 428 |
|
| 429 | public void playSound(
|
| 430 | final @Nullable Entity except,
|
| 431 | final double x,
|
| 432 | final double y,
|
| 433 | final double z,
|
| 434 | final SoundEvent sound,
|
| 435 | final SoundSource source,
|
| 436 | final float volume,
|
| 437 | final float pitch
|
| 438 | ) {
|
| 439 | this.playSeededSound(except, x, y, z, sound, source, volume, pitch, this.soundSeedGenerator.nextLong());
|
| 440 | }
|
| 441 |
|
| 442 | public void playSound(
|
| 443 | final @Nullable Entity except,
|
| 444 | final double x,
|
| 445 | final double y,
|
| 446 | final double z,
|
| 447 | final Holder<SoundEvent> sound,
|
| 448 | final SoundSource source,
|
| 449 | final float volume,
|
| 450 | final float pitch
|
| 451 | ) {
|
| 452 | this.playSeededSound(except, x, y, z, sound, source, volume, pitch, this.soundSeedGenerator.nextLong());
|
| 453 | }
|
| 454 |
|
| 455 | public void playSound(
|
| 456 | final @Nullable Entity except, final Entity sourceEntity, final SoundEvent sound, final SoundSource source, final float volume, final float pitch
|
| 457 | ) {
|
| 458 | this.playSeededSound(except, sourceEntity, BuiltInRegistries.SOUND_EVENT.wrapAsHolder(sound), source, volume, pitch, this.soundSeedGenerator.nextLong());
|
| 459 | }
|
| 460 |
|
| 461 | public void playSound(
|
| 462 | final @Nullable Entity except, final Entity sourceEntity, final Holder<SoundEvent> sound, final SoundSource source, final float volume, final float pitch
|
| 463 | ) {
|
| 464 | this.playSeededSound(except, sourceEntity, sound, source, volume, pitch, this.soundSeedGenerator.nextLong());
|
| 465 | }
|
| 466 |
|
| 467 | public void playLocalSound(
|
| 468 | final BlockPos pos, final SoundEvent sound, final SoundSource source, final float volume, final float pitch, final boolean distanceDelay
|
| 469 | ) {
|
| 470 | this.playLocalSound(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, sound, source, volume, pitch, distanceDelay);
|
| 471 | }
|
| 472 |
|
| 473 | public void playLocalSound(final Entity sourceEntity, final SoundEvent sound, final SoundSource source, final float volume, final float pitch) {
|
| 474 | }
|
| 475 |
|
| 476 | public void playLocalSound(
|
| 477 | final double x,
|
| 478 | final double y,
|
| 479 | final double z,
|
| 480 | final SoundEvent sound,
|
| 481 | final SoundSource source,
|
| 482 | final float volume,
|
| 483 | final float pitch,
|
| 484 | final boolean distanceDelay
|
| 485 | ) {
|
| 486 | }
|
| 487 |
|
| 488 | public void playPlayerSound(final SoundEvent sound, final SoundSource source, final float volume, final float pitch) {
|
| 489 | }
|
| 490 |
|
| 491 | @Override
|
| 492 | public void addParticle(final ParticleOptions particle, final double x, final double y, final double z, final double xd, final double yd, final double zd) {
|
| 493 | }
|
| 494 |
|
| 495 | public void addParticle(
|
| 496 | final ParticleOptions particle,
|
| 497 | final boolean overrideLimiter,
|
| 498 | final boolean alwaysShow,
|
| 499 | final double x,
|
| 500 | final double y,
|
| 501 | final double z,
|
| 502 | final double xd,
|
| 503 | final double yd,
|
| 504 | final double zd
|
| 505 | ) {
|
| 506 | }
|
| 507 |
|
| 508 | public void addAlwaysVisibleParticle(
|
| 509 | final ParticleOptions particle, final double x, final double y, final double z, final double xd, final double yd, final double zd
|
| 510 | ) {
|
| 511 | }
|
| 512 |
|
| 513 | public void addAlwaysVisibleParticle(
|
| 514 | final ParticleOptions particle,
|
| 515 | final boolean overrideLimiter,
|
| 516 | final double x,
|
| 517 | final double y,
|
| 518 | final double z,
|
| 519 | final double xd,
|
| 520 | final double yd,
|
| 521 | final double zd
|
| 522 | ) {
|
| 523 | }
|
| 524 |
|
| 525 | public void addBlockEntityTicker(final TickingBlockEntity ticker) {
|
| 526 | (this.tickingBlockEntities ? this.pendingBlockEntityTickers : this.blockEntityTickers).add(ticker);
|
| 527 | }
|
| 528 |
|
| 529 | public void tickBlockEntities() {
|
| 530 | this.tickingBlockEntities = true;
|
| 531 | if (!this.pendingBlockEntityTickers.isEmpty()) {
|
| 532 | this.blockEntityTickers.addAll(this.pendingBlockEntityTickers);
|
| 533 | this.pendingBlockEntityTickers.clear();
|
| 534 | }
|
| 535 |
|
| 536 | Iterator<TickingBlockEntity> iterator = this.blockEntityTickers.iterator();
|
| 537 | boolean tickBlockEntities = this.tickRateManager().runsNormally();
|
| 538 |
|
| 539 | while (iterator.hasNext()) {
|
| 540 | TickingBlockEntity ticker = iterator.next();
|
| 541 | if (ticker.isRemoved()) {
|
| 542 | iterator.remove();
|
| 543 | } else if (tickBlockEntities && this.shouldTickBlocksAt(ticker.getPos())) {
|
| 544 | ticker.tick();
|
| 545 | }
|
| 546 | }
|
| 547 |
|
| 548 | this.tickingBlockEntities = false;
|
| 549 | }
|
| 550 |
|
| 551 | public <T extends Entity> void guardEntityTick(final Consumer<T> tick, final T entity) {
|
| 552 | try {
|
| 553 | tick.accept(entity);
|
| 554 | } catch (Throwable t) {
|
| 555 | CrashReport report = CrashReport.forThrowable(t, "Ticking entity");
|
| 556 | CrashReportCategory category = report.addCategory("Entity being ticked");
|
| 557 | entity.fillCrashReportCategory(category);
|
| 558 | throw new ReportedException(report);
|
| 559 | }
|
| 560 | }
|
| 561 |
|
| 562 | public boolean shouldTickDeath(final Entity entity) {
|
| 563 | return true;
|
| 564 | }
|
| 565 |
|
| 566 | public boolean shouldTickBlocksAt(final long chunkPos) {
|
| 567 | return true;
|
| 568 | }
|
| 569 |
|
| 570 | public boolean shouldTickBlocksAt(final BlockPos pos) {
|
| 571 | return this.shouldTickBlocksAt(ChunkPos.pack(pos));
|
| 572 | }
|
| 573 |
|
| 574 | public void explode(
|
| 575 | final @Nullable Entity source, final double x, final double y, final double z, final float r, final Level.ExplosionInteraction blockInteraction
|
| 576 | ) {
|
| 577 | this.explode(
|
| 578 | source,
|
| 579 | Explosion.getDefaultDamageSource(this, source),
|
| 580 | null,
|
| 581 | x,
|
| 582 | y,
|
| 583 | z,
|
| 584 | r,
|
| 585 | false,
|
| 586 | blockInteraction,
|
| 587 | ParticleTypes.EXPLOSION,
|
| 588 | ParticleTypes.EXPLOSION_EMITTER,
|
| 589 | DEFAULT_EXPLOSION_BLOCK_PARTICLES,
|
| 590 | SoundEvents.GENERIC_EXPLODE
|
| 591 | );
|
| 592 | }
|
| 593 |
|
| 594 | public void explode(
|
| 595 | final @Nullable Entity source,
|
| 596 | final double x,
|
| 597 | final double y,
|
| 598 | final double z,
|
| 599 | final float r,
|
| 600 | final boolean fire,
|
| 601 | final Level.ExplosionInteraction blockInteraction
|
| 602 | ) {
|
| 603 | this.explode(
|
| 604 | source,
|
| 605 | Explosion.getDefaultDamageSource(this, source),
|
| 606 | null,
|
| 607 | x,
|
| 608 | y,
|
| 609 | z,
|
| 610 | r,
|
| 611 | fire,
|
| 612 | blockInteraction,
|
| 613 | ParticleTypes.EXPLOSION,
|
| 614 | ParticleTypes.EXPLOSION_EMITTER,
|
| 615 | DEFAULT_EXPLOSION_BLOCK_PARTICLES,
|
| 616 | SoundEvents.GENERIC_EXPLODE
|
| 617 | );
|
| 618 | }
|
| 619 |
|
| 620 | public void explode(
|
| 621 | final @Nullable Entity source,
|
| 622 | final @Nullable DamageSource damageSource,
|
| 623 | final @Nullable ExplosionDamageCalculator damageCalculator,
|
| 624 | final Vec3 boomPos,
|
| 625 | final float r,
|
| 626 | final boolean fire,
|
| 627 | final Level.ExplosionInteraction blockInteraction
|
| 628 | ) {
|
| 629 | this.explode(
|
| 630 | source,
|
| 631 | damageSource,
|
| 632 | damageCalculator,
|
| 633 | boomPos.x(),
|
| 634 | boomPos.y(),
|
| 635 | boomPos.z(),
|
| 636 | r,
|
| 637 | fire,
|
| 638 | blockInteraction,
|
| 639 | ParticleTypes.EXPLOSION,
|
| 640 | ParticleTypes.EXPLOSION_EMITTER,
|
| 641 | DEFAULT_EXPLOSION_BLOCK_PARTICLES,
|
| 642 | SoundEvents.GENERIC_EXPLODE
|
| 643 | );
|
| 644 | }
|
| 645 |
|
| 646 | public void explode(
|
| 647 | final @Nullable Entity source,
|
| 648 | final @Nullable DamageSource damageSource,
|
| 649 | final @Nullable ExplosionDamageCalculator damageCalculator,
|
| 650 | final double x,
|
| 651 | final double y,
|
| 652 | final double z,
|
| 653 | final float r,
|
| 654 | final boolean fire,
|
| 655 | final Level.ExplosionInteraction interactionType
|
| 656 | ) {
|
| 657 | this.explode(
|
| 658 | source,
|
| 659 | damageSource,
|
| 660 | damageCalculator,
|
| 661 | x,
|
| 662 | y,
|
| 663 | z,
|
| 664 | r,
|
| 665 | fire,
|
| 666 | interactionType,
|
| 667 | ParticleTypes.EXPLOSION,
|
| 668 | ParticleTypes.EXPLOSION_EMITTER,
|
| 669 | DEFAULT_EXPLOSION_BLOCK_PARTICLES,
|
| 670 | SoundEvents.GENERIC_EXPLODE
|
| 671 | );
|
| 672 | }
|
| 673 |
|
| 674 | public abstract void explode(
|
| 675 | final @Nullable Entity source,
|
| 676 | final @Nullable DamageSource damageSource,
|
| 677 | final @Nullable ExplosionDamageCalculator damageCalculator,
|
| 678 | final double x,
|
| 679 | final double y,
|
| 680 | final double z,
|
| 681 | final float r,
|
| 682 | final boolean fire,
|
| 683 | final Level.ExplosionInteraction interactionType,
|
| 684 | final ParticleOptions smallExplosionParticles,
|
| 685 | final ParticleOptions largeExplosionParticles,
|
| 686 | final WeightedList<ExplosionParticleInfo> blockParticles,
|
| 687 | final Holder<SoundEvent> explosionSound
|
| 688 | );
|
| 689 |
|
| 690 | public abstract String gatherChunkSourceStats();
|
| 691 |
|
| 692 | @Override
|
| 693 | public @Nullable BlockEntity getBlockEntity(final BlockPos pos) {
|
| 694 | if (!this.isInValidBounds(pos)) {
|
| 695 | return null;
|
| 696 | } else {
|
| 697 | return !this.isClientSide() && Thread.currentThread() != this.thread
|
| 698 | ? null
|
| 699 | : this.getChunkAt(pos).getBlockEntity(pos, LevelChunk.EntityCreationType.IMMEDIATE);
|
| 700 | }
|
| 701 | }
|
| 702 |
|
| 703 | public void setBlockEntity(final BlockEntity blockEntity) {
|
| 704 | BlockPos pos = blockEntity.getBlockPos();
|
| 705 | if (this.isInValidBounds(pos)) {
|
| 706 | this.getChunkAt(pos).addAndRegisterBlockEntity(blockEntity);
|
| 707 | }
|
| 708 | }
|
| 709 |
|
| 710 | public void removeBlockEntity(final BlockPos pos) {
|
| 711 | if (this.isInValidBounds(pos)) {
|
| 712 | this.getChunkAt(pos).removeBlockEntity(pos);
|
| 713 | }
|
| 714 | }
|
| 715 |
|
| 716 | public boolean isLoaded(final BlockPos pos) {
|
| 717 | return !this.isInValidBounds(pos)
|
| 718 | ? false
|
| 719 | : this.getChunkSource().hasChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()));
|
| 720 | }
|
| 721 |
|
| 722 | public boolean loadedAndEntityCanStandOnFace(final BlockPos pos, final Entity entity, final Direction faceDirection) {
|
| 723 | if (!this.isInValidBounds(pos)) {
|
| 724 | return false;
|
| 725 | }
|
| 726 |
|
| 727 | ChunkAccess chunk = this.getChunk(SectionPos.blockToSectionCoord(pos.getX()), SectionPos.blockToSectionCoord(pos.getZ()), ChunkStatus.FULL, false);
|
| 728 | return chunk == null ? false : chunk.getBlockState(pos).entityCanStandOnFace(this, pos, entity, faceDirection);
|
| 729 | }
|
| 730 |
|
| 731 | public boolean loadedAndEntityCanStandOn(final BlockPos pos, final Entity entity) {
|
| 732 | return this.loadedAndEntityCanStandOnFace(pos, entity, Direction.UP);
|
| 733 | }
|
| 734 |
|
| 735 | public void updateSkyBrightness() {
|
| 736 | this.skyDarken = (int)(15.0F - this.environmentAttributes().getDimensionValue(EnvironmentAttributes.SKY_LIGHT_LEVEL));
|
| 737 | }
|
| 738 |
|
| 739 | public void setSpawnSettings(final boolean spawnEnemies) {
|
| 740 | this.getChunkSource().setSpawnSettings(spawnEnemies);
|
| 741 | }
|
| 742 |
|
| 743 | public abstract void setRespawnData(final LevelData.RespawnData respawnData);
|
| 744 |
|
| 745 | public abstract LevelData.RespawnData getRespawnData();
|
| 746 |
|
| 747 | public LevelData.RespawnData getWorldBorderAdjustedRespawnData(final LevelData.RespawnData respawnData) {
|
| 748 | WorldBorder worldBorder = this.getWorldBorder();
|
| 749 | if (!worldBorder.isWithinBounds(respawnData.pos())) {
|
| 750 | BlockPos newPos = this.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, BlockPos.containing(worldBorder.getCenterX(), 0.0, worldBorder.getCenterZ()));
|
| 751 | return LevelData.RespawnData.of(respawnData.dimension(), newPos, respawnData.yaw(), respawnData.pitch());
|
| 752 | } else {
|
| 753 | return respawnData;
|
| 754 | }
|
| 755 | }
|
| 756 |
|
| 757 | @Override
|
| 758 | public void close() throws IOException {
|
| 759 | this.getChunkSource().close();
|
| 760 | }
|
| 761 |
|
| 762 | @Override
|
| 763 | public @Nullable BlockGetter getChunkForCollisions(final int chunkX, final int chunkZ) {
|
| 764 | return this.getChunk(chunkX, chunkZ, ChunkStatus.FULL, false);
|
| 765 | }
|
| 766 |
|
| 767 | @Override
|
| 768 | public List<Entity> getEntities(final @Nullable Entity except, final AABB bb, final Predicate<? super Entity> selector) {
|
| 769 | Profiler.get().incrementCounter("getEntities");
|
| 770 | List<Entity> output = Lists.newArrayList();
|
| 771 | this.getEntities().get(bb, entity -> {
|
| 772 | if (entity != except && selector.test(entity)) {
|
| 773 | output.add(entity);
|
| 774 | }
|
| 775 | });
|
| 776 |
|
| 777 | for (EnderDragonPart dragonPart : this.dragonParts()) {
|
| 778 | if (dragonPart != except && dragonPart.parentMob != except && selector.test(dragonPart) && bb.intersects(dragonPart.getBoundingBox())) {
|
| 779 | output.add(dragonPart);
|
| 780 | }
|
| 781 | }
|
| 782 |
|
| 783 | return output;
|
| 784 | }
|
| 785 |
|
| 786 | @Override
|
| 787 | public <T extends Entity> List<T> getEntities(final EntityTypeTest<Entity, T> type, final AABB bb, final Predicate<? super T> selector) {
|
| 788 | List<T> output = Lists.newArrayList();
|
| 789 | this.getEntities(type, bb, selector, output);
|
| 790 | return output;
|
| 791 | }
|
| 792 |
|
| 793 | public <T extends Entity> void getEntities(
|
| 794 | final EntityTypeTest<Entity, T> type, final AABB bb, final Predicate<? super T> selector, final List<? super T> output
|
| 795 | ) {
|
| 796 | this.getEntities(type, bb, selector, output, Integer.MAX_VALUE);
|
| 797 | }
|
| 798 |
|
| 799 | public <T extends Entity> void getEntities(
|
| 800 | final EntityTypeTest<Entity, T> type, final AABB bb, final Predicate<? super T> selector, final List<? super T> output, final int maxResults
|
| 801 | ) {
|
| 802 | Profiler.get().incrementCounter("getEntities");
|
| 803 | this.getEntities().get(type, bb, e -> {
|
| 804 | if (selector.test(e)) {
|
| 805 | output.add(e);
|
| 806 | if (output.size() >= maxResults) {
|
| 807 | return Continuation.ABORT;
|
| 808 | }
|
| 809 | }
|
| 810 |
|
| 811 | if (e instanceof EnderDragon enderDragon) {
|
| 812 | for (EnderDragonPart subEntity : enderDragon.getSubEntities()) {
|
| 813 | T castSubPart = type.tryCast(subEntity);
|
| 814 | if (castSubPart != null && selector.test(castSubPart)) {
|
| 815 | output.add(castSubPart);
|
| 816 | if (output.size() >= maxResults) {
|
| 817 | return Continuation.ABORT;
|
| 818 | }
|
| 819 | }
|
| 820 | }
|
| 821 | }
|
| 822 |
|
| 823 | return Continuation.CONTINUE;
|
| 824 | });
|
| 825 | }
|
| 826 |
|
| 827 | public <T extends Entity> boolean hasEntities(final EntityTypeTest<Entity, T> type, final AABB bb, final Predicate<? super T> selector) {
|
| 828 | Profiler.get().incrementCounter("hasEntities");
|
| 829 | MutableBoolean hasEntities = new MutableBoolean();
|
| 830 | this.getEntities().get(type, bb, e -> {
|
| 831 | if (selector.test(e)) {
|
| 832 | hasEntities.setTrue();
|
| 833 | return Continuation.ABORT;
|
| 834 | }
|
| 835 |
|
| 836 | if (e instanceof EnderDragon enderDragon) {
|
| 837 | for (EnderDragonPart subEntity : enderDragon.getSubEntities()) {
|
| 838 | T castSubPart = type.tryCast(subEntity);
|
| 839 | if (castSubPart != null && selector.test(castSubPart)) {
|
| 840 | hasEntities.setTrue();
|
| 841 | return Continuation.ABORT;
|
| 842 | }
|
| 843 | }
|
| 844 | }
|
| 845 |
|
| 846 | return Continuation.CONTINUE;
|
| 847 | });
|
| 848 | return hasEntities.isTrue();
|
| 849 | }
|
| 850 |
|
| 851 | public List<Entity> getPushableEntities(final Entity pusher, final AABB boundingBox) {
|
| 852 | return this.getEntities(pusher, boundingBox, EntitySelector.pushableBy(pusher));
|
| 853 | }
|
| 854 |
|
| 855 | public abstract @Nullable Entity getEntity(int id);
|
| 856 |
|
| 857 | public @Nullable Entity getEntity(final UUID uuid) {
|
| 858 | return this.getEntities().get(uuid);
|
| 859 | }
|
| 860 |
|
| 861 | public @Nullable Entity getEntityInAnyDimension(final UUID uuid) {
|
| 862 | return this.getEntity(uuid);
|
| 863 | }
|
| 864 |
|
| 865 | public @Nullable Player getPlayerInAnyDimension(final UUID uuid) {
|
| 866 | return this.getPlayerByUUID(uuid);
|
| 867 | }
|
| 868 |
|
| 869 | public abstract Collection<EnderDragonPart> dragonParts();
|
| 870 |
|
| 871 | public void blockEntityChanged(final BlockPos pos) {
|
| 872 | if (this.hasChunkAt(pos)) {
|
| 873 | this.getChunkAt(pos).markUnsaved();
|
| 874 | }
|
| 875 | }
|
| 876 |
|
| 877 | public void onBlockEntityAdded(final BlockEntity blockEntity) {
|
| 878 | }
|
| 879 |
|
| 880 | public long getOverworldClockTime() {
|
| 881 | return this.getClockTimeTicks(this.registryAccess().get(WorldClocks.OVERWORLD));
|
| 882 | }
|
| 883 |
|
| 884 | public long getDefaultClockTime() {
|
| 885 | return this.getClockTimeTicks(this.dimensionType().defaultClock());
|
| 886 | }
|
| 887 |
|
| 888 | private long getClockTimeTicks(final Optional<? extends Holder<WorldClock>> clock) {
|
| 889 | return clock.<Long>map(holder -> this.clockManager().getInstance((Holder<WorldClock>)holder).totalTicks()).orElse(0L);
|
| 890 | }
|
| 891 |
|
| 892 | public boolean mayInteract(final Entity entity, final BlockPos pos) {
|
| 893 | return true;
|
| 894 | }
|
| 895 |
|
| 896 | public void broadcastEntityEvent(final Entity entity, final @EntityEvent.Value byte event) {
|
| 897 | }
|
| 898 |
|
| 899 | public void broadcastDamageEvent(final Entity entity, final DamageSource source) {
|
| 900 | }
|
| 901 |
|
| 902 | public void blockEvent(final BlockPos pos, final Block block, final int b0, final int b1) {
|
| 903 | this.getBlockState(pos).triggerEvent(this, pos, b0, b1);
|
| 904 | }
|
| 905 |
|
| 906 | @Override
|
| 907 | public LevelData getLevelData() {
|
| 908 | return this.levelData;
|
| 909 | }
|
| 910 |
|
| 911 | public abstract TickRateManager tickRateManager();
|
| 912 |
|
| 913 | public float getRelativeTickSpeed() {
|
| 914 | return 1.0F;
|
| 915 | }
|
| 916 |
|
| 917 | public float getThunderLevel(final float a) {
|
| 918 | return Mth.lerp(a, this.oThunderLevel, this.thunderLevel) * this.getRainLevel(a);
|
| 919 | }
|
| 920 |
|
| 921 | public void setThunderLevel(final float thunderLevel) {
|
| 922 | float clampedThunderLevel = Mth.clamp(thunderLevel, 0.0F, 1.0F);
|
| 923 | this.oThunderLevel = clampedThunderLevel;
|
| 924 | this.thunderLevel = clampedThunderLevel;
|
| 925 | }
|
| 926 |
|
| 927 | public float getRainLevel(final float a) {
|
| 928 | return Mth.lerp(a, this.oRainLevel, this.rainLevel);
|
| 929 | }
|
| 930 |
|
| 931 | public void setRainLevel(final float rainLevel) {
|
| 932 | float clampedRainLevel = Mth.clamp(rainLevel, 0.0F, 1.0F);
|
| 933 | this.oRainLevel = clampedRainLevel;
|
| 934 | this.rainLevel = clampedRainLevel;
|
| 935 | }
|
| 936 |
|
| 937 | public boolean canHaveWeather() {
|
| 938 | return this.dimensionType().hasSkyLight() && !this.dimensionType().hasCeiling() && this.dimension() != END;
|
| 939 | }
|
| 940 |
|
| 941 | public boolean isThundering() {
|
| 942 | return this.canHaveWeather() && this.getThunderLevel(1.0F) > 0.9;
|
| 943 | }
|
| 944 |
|
| 945 | public boolean isRaining() {
|
| 946 | return this.canHaveWeather() && this.getRainLevel(1.0F) > 0.2;
|
| 947 | }
|
| 948 |
|
| 949 | public boolean isRainingAt(final BlockPos pos) {
|
| 950 | return this.precipitationAt(pos) == Biome.Precipitation.RAIN;
|
| 951 | }
|
| 952 |
|
| 953 | public Biome.Precipitation precipitationAt(final BlockPos pos) {
|
| 954 | if (!this.isRaining()) {
|
| 955 | return Biome.Precipitation.NONE;
|
| 956 | }
|
| 957 |
|
| 958 | if (!this.canSeeSky(pos)) {
|
| 959 | return Biome.Precipitation.NONE;
|
| 960 | }
|
| 961 |
|
| 962 | if (this.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, pos).getY() > pos.getY()) {
|
| 963 | return Biome.Precipitation.NONE;
|
| 964 | }
|
| 965 |
|
| 966 | Biome biome = this.getBiome(pos).value();
|
| 967 | return biome.getPrecipitationAt(pos, this.getSeaLevel());
|
| 968 | }
|
| 969 |
|
| 970 | public abstract @Nullable MapItemSavedData getMapData(MapId id);
|
| 971 |
|
| 972 | public void globalLevelEvent(final @LevelEvent.Value int type, final BlockPos pos, final int data) {
|
| 973 | }
|
| 974 |
|
| 975 | public CrashReportCategory fillReportDetails(final CrashReport report) {
|
| 976 | CrashReportCategory category = report.addCategory("Affected level", 1);
|
| 977 | category.setDetail("All players", () -> {
|
| 978 | List<? extends Player> players = this.players();
|
| 979 | return players.size() + " total; " + players.stream().map(Player::debugInfo).collect(Collectors.joining(", "));
|
| 980 | });
|
| 981 | category.setDetail("Chunk stats", this.getChunkSource()::gatherStats);
|
| 982 | category.setDetail("Level dimension", () -> this.dimension().identifier().toString());
|
| 983 | category.setDetail("Level time", () -> String.format(Locale.ROOT, "%d game time, %d day time", this.getGameTime(), this.getOverworldClockTime()));
|
| 984 |
|
| 985 | try {
|
| 986 | this.levelData.fillCrashReportCategory(category, this);
|
| 987 | } catch (Throwable t) {
|
| 988 | category.setDetailError("Level Data Unobtainable", t);
|
| 989 | }
|
| 990 |
|
| 991 | return category;
|
| 992 | }
|
| 993 |
|
| 994 | public abstract void destroyBlockProgress(final int id, final BlockPos blockPos, final int progress);
|
| 995 |
|
| 996 | public void createFireworks(
|
| 997 | final double x,
|
| 998 | final double y,
|
| 999 | final double z,
|
| 1000 | final double xd,
|
| 1001 | final double yd,
|
| 1002 | final double zd,
|
| 1003 | final List<FireworkExplosion> explosions,
|
| 1004 | final boolean playSound
|
| 1005 | ) {
|
| 1006 | }
|
| 1007 |
|
| 1008 | public abstract Scoreboard getScoreboard();
|
| 1009 |
|
| 1010 | public void updateNeighbourForOutputSignal(final BlockPos pos, final Block changedBlock) {
|
| 1011 | for (Direction direction : Direction.Plane.HORIZONTAL) {
|
| 1012 | BlockPos relativePos = pos.relative(direction);
|
| 1013 | if (this.hasChunkAt(relativePos)) {
|
| 1014 | BlockState state = this.getBlockState(relativePos);
|
| 1015 | if (state.is(Blocks.COMPARATOR)) {
|
| 1016 | this.neighborChanged(state, relativePos, changedBlock, null, false);
|
| 1017 | } else if (state.isRedstoneConductor(this, relativePos)) {
|
| 1018 | relativePos = relativePos.relative(direction);
|
| 1019 | state = this.getBlockState(relativePos);
|
| 1020 | if (state.is(Blocks.COMPARATOR)) {
|
| 1021 | this.neighborChanged(state, relativePos, changedBlock, null, false);
|
| 1022 | }
|
| 1023 | }
|
| 1024 | }
|
| 1025 | }
|
| 1026 | }
|
| 1027 |
|
| 1028 | @Override
|
| 1029 | public int getSkyDarken() {
|
| 1030 | return this.skyDarken;
|
| 1031 | }
|
| 1032 |
|
| 1033 | public void setSkyFlashTime(final int skyFlashTime) {
|
| 1034 | }
|
| 1035 |
|
| 1036 | public void sendPacketToServer(final Packet<?> packet) {
|
| 1037 | throw new UnsupportedOperationException("Can't send packets to server unless you're on the client.");
|
| 1038 | }
|
| 1039 |
|
| 1040 | @Override
|
| 1041 | public DimensionType dimensionType() {
|
| 1042 | return this.dimensionTypeRegistration.value();
|
| 1043 | }
|
| 1044 |
|
| 1045 | public Holder<DimensionType> dimensionTypeRegistration() {
|
| 1046 | return this.dimensionTypeRegistration;
|
| 1047 | }
|
| 1048 |
|
| 1049 | public ResourceKey<Level> dimension() {
|
| 1050 | return this.dimension;
|
| 1051 | }
|
| 1052 |
|
| 1053 | @Override
|
| 1054 | public RandomSource getRandom() {
|
| 1055 | return this.random;
|
| 1056 | }
|
| 1057 |
|
| 1058 | @Override
|
| 1059 | public boolean isStateAtPosition(final BlockPos pos, final Predicate<BlockState> predicate) {
|
| 1060 | return predicate.test(this.getBlockState(pos));
|
| 1061 | }
|
| 1062 |
|
| 1063 | @Override
|
| 1064 | public boolean isFluidAtPosition(final BlockPos pos, final Predicate<FluidState> predicate) {
|
| 1065 | return predicate.test(this.getFluidState(pos));
|
| 1066 | }
|
| 1067 |
|
| 1068 | public abstract RecipeAccess recipeAccess();
|
| 1069 |
|
| 1070 | public BlockPos getBlockRandomPos(final int xo, final int yo, final int zo, final int yMask) {
|
| 1071 | this.randValue = this.randValue * 3 + 1013904223;
|
| 1072 | int val = this.randValue >> 2;
|
| 1073 | return new BlockPos(xo + (val & 15), yo + (val >> 16 & yMask), zo + (val >> 8 & 15));
|
| 1074 | }
|
| 1075 |
|
| 1076 | public boolean noSave() {
|
| 1077 | return false;
|
| 1078 | }
|
| 1079 |
|
| 1080 | @Override
|
| 1081 | public BiomeManager getBiomeManager() {
|
| 1082 | return this.biomeManager;
|
| 1083 | }
|
| 1084 |
|
| 1085 | public final boolean isDebug() {
|
| 1086 | return this.isDebug;
|
| 1087 | }
|
| 1088 |
|
| 1089 | protected abstract LevelEntityGetter<Entity> getEntities();
|
| 1090 |
|
| 1091 | @Override
|
| 1092 | public long nextSubTickCount() {
|
| 1093 | return this.subTickCount++;
|
| 1094 | }
|
| 1095 |
|
| 1096 | @Override
|
| 1097 | public RegistryAccess registryAccess() {
|
| 1098 | return this.registryAccess;
|
| 1099 | }
|
| 1100 |
|
| 1101 | public DamageSources damageSources() {
|
| 1102 | return this.damageSources;
|
| 1103 | }
|
| 1104 |
|
| 1105 | public abstract ClockManager clockManager();
|
| 1106 |
|
| 1107 | public abstract EnvironmentAttributeSystem environmentAttributes();
|
| 1108 |
|
| 1109 | public int getClientLeafTintColor(final BlockPos pos) {
|
| 1110 | return 0;
|
| 1111 | }
|
| 1112 |
|
| 1113 | public PalettedContainerFactory palettedContainerFactory() {
|
| 1114 | return this.palettedContainerFactory;
|
| 1115 | }
|
| 1116 |
|
| 1117 | public enum ExplosionInteraction implements StringRepresentable {
|
| 1118 | NONE("none"),
|
| 1119 | BLOCK("block"),
|
| 1120 | MOB("mob"),
|
| 1121 | TNT("tnt"),
|
| 1122 | TRIGGER("trigger");
|
| 1123 |
|
| 1124 | public static final Codec<Level.ExplosionInteraction> CODEC = StringRepresentable.fromEnum(Level.ExplosionInteraction::values);
|
| 1125 | private final String id;
|
| 1126 |
|
| 1127 | ExplosionInteraction(final String id) {
|
| 1128 | this.id = id;
|
| 1129 | }
|
| 1130 |
|
| 1131 | @Override
|
| 1132 | public String getSerializedName() {
|
| 1133 | return this.id;
|
| 1134 | }
|
| 1135 | }
|
| 1136 | }
|
| 1137 |
|