| 1 | package net.minecraft.world.level.chunk;
|
| 2 |
|
| 3 | import it.unimi.dsi.fastutil.longs.LongSet;
|
| 4 | import java.util.Map;
|
| 5 | import java.util.function.BiConsumer;
|
| 6 | import java.util.function.Predicate;
|
| 7 | import net.minecraft.core.BlockPos;
|
| 8 | import net.minecraft.core.Holder;
|
| 9 | import net.minecraft.core.HolderLookup;
|
| 10 | import net.minecraft.nbt.CompoundTag;
|
| 11 | import net.minecraft.world.entity.Entity;
|
| 12 | import net.minecraft.world.level.ChunkPos;
|
| 13 | import net.minecraft.world.level.biome.Biome;
|
| 14 | import net.minecraft.world.level.biome.BiomeResolver;
|
| 15 | import net.minecraft.world.level.block.Block;
|
| 16 | import net.minecraft.world.level.block.entity.BlockEntity;
|
| 17 | import net.minecraft.world.level.block.state.BlockState;
|
| 18 | import net.minecraft.world.level.chunk.status.ChunkStatus;
|
| 19 | import net.minecraft.world.level.levelgen.Heightmap;
|
| 20 | import net.minecraft.world.level.levelgen.blending.BlendingData;
|
| 21 | import net.minecraft.world.level.levelgen.structure.Structure;
|
| 22 | import net.minecraft.world.level.levelgen.structure.StructureStart;
|
| 23 | import net.minecraft.world.level.lighting.ChunkSkyLightSources;
|
| 24 | import net.minecraft.world.level.material.Fluid;
|
| 25 | import net.minecraft.world.level.material.FluidState;
|
| 26 | import net.minecraft.world.ticks.BlackholeTickAccess;
|
| 27 | import net.minecraft.world.ticks.TickContainerAccess;
|
| 28 | import org.jspecify.annotations.Nullable;
|
| 29 |
|
| 30 | public class ImposterProtoChunk extends ProtoChunk {
|
| 31 | private final LevelChunk wrapped;
|
| 32 | private final boolean allowWrites;
|
| 33 |
|
| 34 | public ImposterProtoChunk(final LevelChunk wrapped, final boolean allowWrites) {
|
| 35 | super(wrapped.getPos(), UpgradeData.EMPTY, wrapped.levelHeightAccessor, wrapped.getLevel().palettedContainerFactory(), wrapped.getBlendingData());
|
| 36 | this.wrapped = wrapped;
|
| 37 | this.allowWrites = allowWrites;
|
| 38 | }
|
| 39 |
|
| 40 | @Override
|
| 41 | public @Nullable BlockEntity getBlockEntity(final BlockPos pos) {
|
| 42 | return this.wrapped.getBlockEntity(pos);
|
| 43 | }
|
| 44 |
|
| 45 | @Override
|
| 46 | public BlockState getBlockState(final BlockPos pos) {
|
| 47 | return this.wrapped.getBlockState(pos);
|
| 48 | }
|
| 49 |
|
| 50 | @Override
|
| 51 | public FluidState getFluidState(final BlockPos pos) {
|
| 52 | return this.wrapped.getFluidState(pos);
|
| 53 | }
|
| 54 |
|
| 55 | @Override
|
| 56 | public LevelChunkSection getSection(final int sectionIndex) {
|
| 57 | return this.allowWrites ? this.wrapped.getSection(sectionIndex) : super.getSection(sectionIndex);
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | public @Nullable BlockState setBlockState(final BlockPos pos, final BlockState state, final @Block.UpdateFlags int flags) {
|
| 62 | return this.allowWrites ? this.wrapped.setBlockState(pos, state, flags) : null;
|
| 63 | }
|
| 64 |
|
| 65 | @Override
|
| 66 | public void setBlockEntity(final BlockEntity blockEntity) {
|
| 67 | if (this.allowWrites) {
|
| 68 | this.wrapped.setBlockEntity(blockEntity);
|
| 69 | }
|
| 70 | }
|
| 71 |
|
| 72 | @Override
|
| 73 | public void addEntity(final Entity entity) {
|
| 74 | if (this.allowWrites) {
|
| 75 | this.wrapped.addEntity(entity);
|
| 76 | }
|
| 77 | }
|
| 78 |
|
| 79 | @Override
|
| 80 | public void setPersistedStatus(final ChunkStatus status) {
|
| 81 | if (this.allowWrites) {
|
| 82 | super.setPersistedStatus(status);
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | public LevelChunkSection[] getSections() {
|
| 88 | return this.wrapped.getSections();
|
| 89 | }
|
| 90 |
|
| 91 | @Override
|
| 92 | public void setHeightmap(final Heightmap.Types key, final long[] data) {
|
| 93 | }
|
| 94 |
|
| 95 | private Heightmap.Types fixType(final Heightmap.Types type) {
|
| 96 | if (type == Heightmap.Types.WORLD_SURFACE_WG) {
|
| 97 | return Heightmap.Types.WORLD_SURFACE;
|
| 98 | } else {
|
| 99 | return type == Heightmap.Types.OCEAN_FLOOR_WG ? Heightmap.Types.OCEAN_FLOOR : type;
|
| 100 | }
|
| 101 | }
|
| 102 |
|
| 103 | @Override
|
| 104 | public Heightmap getOrCreateHeightmapUnprimed(final Heightmap.Types type) {
|
| 105 | return this.wrapped.getOrCreateHeightmapUnprimed(type);
|
| 106 | }
|
| 107 |
|
| 108 | @Override
|
| 109 | public int getHeight(final Heightmap.Types type, final int x, final int z) {
|
| 110 | return this.wrapped.getHeight(this.fixType(type), x, z);
|
| 111 | }
|
| 112 |
|
| 113 | @Override
|
| 114 | public Holder<Biome> getNoiseBiome(final int quartX, final int quartY, final int quartZ) {
|
| 115 | return this.wrapped.getNoiseBiome(quartX, quartY, quartZ);
|
| 116 | }
|
| 117 |
|
| 118 | @Override
|
| 119 | public ChunkPos getPos() {
|
| 120 | return this.wrapped.getPos();
|
| 121 | }
|
| 122 |
|
| 123 | @Override
|
| 124 | public @Nullable StructureStart getStartForStructure(final Structure structure) {
|
| 125 | return this.wrapped.getStartForStructure(structure);
|
| 126 | }
|
| 127 |
|
| 128 | @Override
|
| 129 | public void setStartForStructure(final Structure structure, final StructureStart structureStart) {
|
| 130 | }
|
| 131 |
|
| 132 | @Override
|
| 133 | public Map<Structure, StructureStart> getAllStarts() {
|
| 134 | return this.wrapped.getAllStarts();
|
| 135 | }
|
| 136 |
|
| 137 | @Override
|
| 138 | public void setAllStarts(final Map<Structure, StructureStart> starts) {
|
| 139 | }
|
| 140 |
|
| 141 | @Override
|
| 142 | public LongSet getReferencesForStructure(final Structure structure) {
|
| 143 | return this.wrapped.getReferencesForStructure(structure);
|
| 144 | }
|
| 145 |
|
| 146 | @Override
|
| 147 | public void addReferenceForStructure(final Structure structure, final long reference) {
|
| 148 | }
|
| 149 |
|
| 150 | @Override
|
| 151 | public Map<Structure, LongSet> getAllReferences() {
|
| 152 | return this.wrapped.getAllReferences();
|
| 153 | }
|
| 154 |
|
| 155 | @Override
|
| 156 | public void setAllReferences(final Map<Structure, LongSet> data) {
|
| 157 | }
|
| 158 |
|
| 159 | @Override
|
| 160 | public void markUnsaved() {
|
| 161 | this.wrapped.markUnsaved();
|
| 162 | }
|
| 163 |
|
| 164 | @Override
|
| 165 | public boolean canBeSerialized() {
|
| 166 | return false;
|
| 167 | }
|
| 168 |
|
| 169 | @Override
|
| 170 | public boolean tryMarkSaved() {
|
| 171 | return false;
|
| 172 | }
|
| 173 |
|
| 174 | @Override
|
| 175 | public boolean isUnsaved() {
|
| 176 | return false;
|
| 177 | }
|
| 178 |
|
| 179 | @Override
|
| 180 | public ChunkStatus getPersistedStatus() {
|
| 181 | return this.wrapped.getPersistedStatus();
|
| 182 | }
|
| 183 |
|
| 184 | @Override
|
| 185 | public void removeBlockEntity(final BlockPos pos) {
|
| 186 | }
|
| 187 |
|
| 188 | @Override
|
| 189 | public void markPosForPostProcessing(final BlockPos blockPos) {
|
| 190 | }
|
| 191 |
|
| 192 | @Override
|
| 193 | public void setBlockEntityNbt(final CompoundTag entityTag) {
|
| 194 | }
|
| 195 |
|
| 196 | @Override
|
| 197 | public @Nullable CompoundTag getBlockEntityNbt(final BlockPos blockPos) {
|
| 198 | return this.wrapped.getBlockEntityNbt(blockPos);
|
| 199 | }
|
| 200 |
|
| 201 | @Override
|
| 202 | public @Nullable CompoundTag getBlockEntityNbtForSaving(final BlockPos blockPos, final HolderLookup.Provider registryAccess) {
|
| 203 | return this.wrapped.getBlockEntityNbtForSaving(blockPos, registryAccess);
|
| 204 | }
|
| 205 |
|
| 206 | @Override
|
| 207 | public void findBlocks(final Predicate<BlockState> predicate, final BiConsumer<BlockPos, BlockState> consumer) {
|
| 208 | this.wrapped.findBlocks(predicate, consumer);
|
| 209 | }
|
| 210 |
|
| 211 | @Override
|
| 212 | public TickContainerAccess<Block> getBlockTicks() {
|
| 213 | return this.allowWrites ? this.wrapped.getBlockTicks() : BlackholeTickAccess.emptyContainer();
|
| 214 | }
|
| 215 |
|
| 216 | @Override
|
| 217 | public TickContainerAccess<Fluid> getFluidTicks() {
|
| 218 | return this.allowWrites ? this.wrapped.getFluidTicks() : BlackholeTickAccess.emptyContainer();
|
| 219 | }
|
| 220 |
|
| 221 | @Override
|
| 222 | public ChunkAccess.PackedTicks getTicksForSerialization(final long currentTick) {
|
| 223 | return this.wrapped.getTicksForSerialization(currentTick);
|
| 224 | }
|
| 225 |
|
| 226 | @Override
|
| 227 | public @Nullable BlendingData getBlendingData() {
|
| 228 | return this.wrapped.getBlendingData();
|
| 229 | }
|
| 230 |
|
| 231 | public LevelChunk getWrapped() {
|
| 232 | return this.wrapped;
|
| 233 | }
|
| 234 |
|
| 235 | @Override
|
| 236 | public boolean isLightCorrect() {
|
| 237 | return this.wrapped.isLightCorrect();
|
| 238 | }
|
| 239 |
|
| 240 | @Override
|
| 241 | public void setLightCorrect(final boolean isLightCorrect) {
|
| 242 | this.wrapped.setLightCorrect(isLightCorrect);
|
| 243 | }
|
| 244 |
|
| 245 | @Override
|
| 246 | public void fillBiomesFromNoise(final BiomeResolver biomeResolver) {
|
| 247 | if (this.allowWrites) {
|
| 248 | this.wrapped.fillBiomesFromNoise(biomeResolver);
|
| 249 | }
|
| 250 | }
|
| 251 |
|
| 252 | @Override
|
| 253 | public void initializeLightSources() {
|
| 254 | this.wrapped.initializeLightSources();
|
| 255 | }
|
| 256 |
|
| 257 | @Override
|
| 258 | public ChunkSkyLightSources getSkyLightSources() {
|
| 259 | return this.wrapped.getSkyLightSources();
|
| 260 | }
|
| 261 | }
|
| 262 |
|