broken-arrow

Untitled

Dec 15th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.81 KB | None | 0 0
  1. //
  2. // Source code recreated from a .class file by IntelliJ IDEA
  3. // (powered by FernFlower decompiler)
  4. //
  5.  
  6. package net.minecraft.world.level.chunk;
  7.  
  8. import java.util.function.Predicate;
  9. import net.minecraft.core.QuartPos;
  10. import net.minecraft.core.Registry;
  11. import net.minecraft.network.FriendlyByteBuf;
  12. import net.minecraft.world.level.biome.Biome;
  13. import net.minecraft.world.level.biome.BiomeResolver;
  14. import net.minecraft.world.level.biome.Biomes;
  15. import net.minecraft.world.level.biome.Climate.Sampler;
  16. import net.minecraft.world.level.block.Block;
  17. import net.minecraft.world.level.block.Blocks;
  18. import net.minecraft.world.level.block.state.BlockState;
  19. import net.minecraft.world.level.chunk.PalettedContainer.Strategy;
  20. import net.minecraft.world.level.material.FluidState;
  21.  
  22. public class LevelChunkSection {
  23.     public static final int SECTION_WIDTH = 16;
  24.     public static final int SECTION_HEIGHT = 16;
  25.     public static final int SECTION_SIZE = 4096;
  26.     public static final int BIOME_CONTAINER_BITS = 2;
  27.     private final int bottomBlockY;
  28.     private short nonEmptyBlockCount;
  29.     private short tickingBlockCount;
  30.     private short tickingFluidCount;
  31.     private final PalettedContainer<BlockState> states;
  32.     private final PalettedContainer<Biome> biomes;
  33.  
  34.     public LevelChunkSection(int i, PalettedContainer<BlockState> datapaletteblock, PalettedContainer<Biome> datapaletteblock1) {
  35.         this.bottomBlockY = getBottomBlockY(i);
  36.         this.states = datapaletteblock;
  37.         this.biomes = datapaletteblock1;
  38.         this.recalcBlockCounts();
  39.     }
  40.  
  41.     public LevelChunkSection(int i, Registry<Biome> iregistry) {
  42.         this.bottomBlockY = getBottomBlockY(i);
  43.         this.states = new PalettedContainer(Block.BLOCK_STATE_REGISTRY, Blocks.AIR.defaultBlockState(), Strategy.SECTION_STATES);
  44.         this.biomes = new PalettedContainer(iregistry, (Biome)iregistry.getOrThrow(Biomes.PLAINS), Strategy.SECTION_BIOMES);
  45.     }
  46.  
  47.     public static int getBottomBlockY(int i) {
  48.         return i << 4;
  49.     }
  50.  
  51.     public BlockState getBlockState(int i, int j, int k) {
  52.         return (BlockState)this.states.get(i, j, k);
  53.     }
  54.  
  55.     public FluidState getFluidState(int i, int j, int k) {
  56.         return ((BlockState)this.states.get(i, j, k)).getFluidState();
  57.     }
  58.  
  59.     public void acquire() {
  60.         this.states.acquire();
  61.     }
  62.  
  63.     public void release() {
  64.         this.states.release();
  65.     }
  66.  
  67.     public BlockState setBlockState(int i, int j, int k, BlockState iblockdata) {
  68.         return this.setBlockState(i, j, k, iblockdata, true);
  69.     }
  70.  
  71.     public BlockState setBlockState(int i, int j, int k, BlockState iblockdata, boolean flag) {
  72.         BlockState iblockdata1;
  73.         if (flag) {
  74.             iblockdata1 = (BlockState)this.states.getAndSet(i, j, k, iblockdata);
  75.         } else {
  76.             iblockdata1 = (BlockState)this.states.getAndSetUnchecked(i, j, k, iblockdata);
  77.         }
  78.  
  79.         FluidState fluid = iblockdata1.getFluidState();
  80.         FluidState fluid1 = iblockdata.getFluidState();
  81.         if (!iblockdata1.isAir()) {
  82.             --this.nonEmptyBlockCount;
  83.             if (iblockdata1.isRandomlyTicking()) {
  84.                 --this.tickingBlockCount;
  85.             }
  86.         }
  87.  
  88.         if (!fluid.isEmpty()) {
  89.             --this.tickingFluidCount;
  90.         }
  91.  
  92.         if (!iblockdata.isAir()) {
  93.             ++this.nonEmptyBlockCount;
  94.             if (iblockdata.isRandomlyTicking()) {
  95.                 ++this.tickingBlockCount;
  96.             }
  97.         }
  98.  
  99.         if (!fluid1.isEmpty()) {
  100.             ++this.tickingFluidCount;
  101.         }
  102.  
  103.         return iblockdata1;
  104.     }
  105.  
  106.     public boolean hasOnlyAir() {
  107.         return this.nonEmptyBlockCount == 0;
  108.     }
  109.  
  110.     public boolean isRandomlyTicking() {
  111.         return this.isRandomlyTickingBlocks() || this.isRandomlyTickingFluids();
  112.     }
  113.  
  114.     public boolean isRandomlyTickingBlocks() {
  115.         return this.tickingBlockCount > 0;
  116.     }
  117.  
  118.     public boolean isRandomlyTickingFluids() {
  119.         return this.tickingFluidCount > 0;
  120.     }
  121.  
  122.     public int bottomBlockY() {
  123.         return this.bottomBlockY;
  124.     }
  125.  
  126.     public void recalcBlockCounts() {
  127.         this.nonEmptyBlockCount = 0;
  128.         this.tickingBlockCount = 0;
  129.         this.tickingFluidCount = 0;
  130.         this.states.count((iblockdata, i) -> {
  131.             FluidState fluid = iblockdata.getFluidState();
  132.             if (!iblockdata.isAir()) {
  133.                 this.nonEmptyBlockCount = (short)(this.nonEmptyBlockCount + i);
  134.                 if (iblockdata.isRandomlyTicking()) {
  135.                     this.tickingBlockCount = (short)(this.tickingBlockCount + i);
  136.                 }
  137.             }
  138.  
  139.             if (!fluid.isEmpty()) {
  140.                 this.nonEmptyBlockCount = (short)(this.nonEmptyBlockCount + i);
  141.                 if (fluid.isRandomlyTicking()) {
  142.                     this.tickingFluidCount = (short)(this.tickingFluidCount + i);
  143.                 }
  144.             }
  145.  
  146.         });
  147.     }
  148.  
  149.     public PalettedContainer<BlockState> getStates() {
  150.         return this.states;
  151.     }
  152.  
  153.     public PalettedContainer<Biome> getBiomes() {
  154.         return this.biomes;
  155.     }
  156.  
  157.     public void read(FriendlyByteBuf packetdataserializer) {
  158.         this.nonEmptyBlockCount = packetdataserializer.readShort();
  159.         this.states.read(packetdataserializer);
  160.         this.biomes.read(packetdataserializer);
  161.     }
  162.  
  163.     public void write(FriendlyByteBuf packetdataserializer) {
  164.         packetdataserializer.writeShort(this.nonEmptyBlockCount);
  165.         this.states.write(packetdataserializer);
  166.         this.biomes.write(packetdataserializer);
  167.     }
  168.  
  169.     public int getSerializedSize() {
  170.         return 2 + this.states.getSerializedSize() + this.biomes.getSerializedSize();
  171.     }
  172.  
  173.     public boolean maybeHas(Predicate<BlockState> predicate) {
  174.         return this.states.maybeHas(predicate);
  175.     }
  176.  
  177.     public Biome getNoiseBiome(int i, int j, int k) {
  178.         return (Biome)this.biomes.get(i, j, k);
  179.     }
  180.  
  181.     public void setBiome(int i, int j, int k, Biome biome) {
  182.         this.biomes.set(i, j, k, biome);
  183.     }
  184.  
  185.     public void fillBiomesFromNoise(BiomeResolver biomeresolver, Sampler climate_sampler, int i, int j) {
  186.         PalettedContainer<Biome> datapaletteblock = this.getBiomes();
  187.         datapaletteblock.acquire();
  188.  
  189.         try {
  190.             int k = QuartPos.fromBlock(this.bottomBlockY());
  191.             boolean flag = true;
  192.  
  193.             for(int l = 0; l < 4; ++l) {
  194.                 for(int i1 = 0; i1 < 4; ++i1) {
  195.                     for(int j1 = 0; j1 < 4; ++j1) {
  196.                         datapaletteblock.getAndSetUnchecked(l, i1, j1, biomeresolver.getNoiseBiome(i + l, k + i1, j + j1, climate_sampler));
  197.                     }
  198.                 }
  199.             }
  200.         } finally {
  201.             datapaletteblock.release();
  202.         }
  203.  
  204.     }
  205. }
  206.  
Add Comment
Please, Sign In to add comment