From 2bedc94bc6965fbfcd2ef4831005a49c363b9062 Mon Sep 17 00:00:00 2001 From: reidbhuntley Date: Sat, 29 May 2021 22:09:58 -0400 Subject: [PATCH] Fix schematic deployment crash caused by some Mekanism blocks --- .../worldWrappers/WrappedChunkProvider.java | 26 +++++- .../worldWrappers/chunk/EmptierChunk.java | 82 +++++++++++++++++++ 2 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/EmptierChunk.java diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java index 4bb1dfffa..43a4bbde7 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/WrappedChunkProvider.java @@ -1,20 +1,40 @@ package com.simibubi.create.foundation.utility.worldWrappers; +import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.function.Predicate; import java.util.stream.Stream; import javax.annotation.Nullable; +import com.simibubi.create.foundation.utility.worldWrappers.chunk.EmptierChunk; import com.simibubi.create.foundation.utility.worldWrappers.chunk.WrappedChunk; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.Entity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.Util; +import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.registry.Registry; import net.minecraft.world.IBlockReader; +import net.minecraft.world.World; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeContainer; +import net.minecraft.world.biome.BiomeRegistry; import net.minecraft.world.chunk.AbstractChunkProvider; +import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.ChunkStatus; +import net.minecraft.world.chunk.EmptyChunk; import net.minecraft.world.chunk.IChunk; import net.minecraft.world.lighting.WorldLightManager; +import net.minecraft.world.server.ChunkHolder; public class WrappedChunkProvider extends AbstractChunkProvider { private PlacementSimulationWorld world; @@ -52,11 +72,11 @@ public class WrappedChunkProvider extends AbstractChunkProvider { return getChunk(x, z); } - public WrappedChunk getChunk(int x, int z) { + public IChunk getChunk(int x, int z) { long pos = ChunkPos.asLong(x, z); - + if (chunks == null) - return null; + return new EmptierChunk(); return chunks.computeIfAbsent(pos, $ -> new WrappedChunk(world, x, z)); } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/EmptierChunk.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/EmptierChunk.java new file mode 100644 index 000000000..dae7595f3 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/EmptierChunk.java @@ -0,0 +1,82 @@ +package com.simibubi.create.foundation.utility.worldWrappers.chunk; + +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.Entity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.lighting.WorldLightManager; +import net.minecraft.world.server.ChunkHolder; + +import javax.annotation.Nullable; + +import java.util.List; +import java.util.function.Predicate; + +public class EmptierChunk extends Chunk { + + public EmptierChunk() { + super(null, null, null); + } + + public BlockState getBlockState(BlockPos p_180495_1_) { + return Blocks.VOID_AIR.getDefaultState(); + } + + @Nullable + public BlockState setBlockState(BlockPos p_177436_1_, BlockState p_177436_2_, boolean p_177436_3_) { + return null; + } + + public FluidState getFluidState(BlockPos p_204610_1_) { + return Fluids.EMPTY.getDefaultState(); + } + + @Nullable + public WorldLightManager getWorldLightManager() { + return null; + } + + public int getLightValue(BlockPos p_217298_1_) { + return 0; + } + + public void addEntity(Entity p_76612_1_) { } + + public void removeEntity(Entity p_76622_1_) { } + + public void removeEntityAtIndex(Entity p_76608_1_, int p_76608_2_) { } + + @Nullable + public TileEntity getTileEntity(BlockPos p_177424_1_, Chunk.CreateEntityType p_177424_2_) { + return null; + } + + public void addTileEntity(TileEntity p_150813_1_) { } + + public void addTileEntity(BlockPos p_177426_1_, TileEntity p_177426_2_) { } + + public void removeTileEntity(BlockPos p_177425_1_) { } + + public void markDirty() { } + + public void getEntitiesWithinAABBForEntity(@Nullable Entity p_177414_1_, AxisAlignedBB p_177414_2_, List p_177414_3_, Predicate p_177414_4_) { } + + public void getEntitiesOfTypeWithinAABB(Class p_177430_1_, AxisAlignedBB p_177430_2_, List p_177430_3_, Predicate p_177430_4_) { } + + public boolean isEmpty() { + return true; + } + + public boolean isEmptyBetween(int p_76606_1_, int p_76606_2_) { + return true; + } + + public ChunkHolder.LocationType getLocationType() { + return ChunkHolder.LocationType.BORDER; + } +}