From 0a9c10a13d2c79ead5ed77861737c049a32c60d5 Mon Sep 17 00:00:00 2001 From: reidbhuntley Date: Tue, 21 Dec 2021 12:22:49 -0500 Subject: [PATCH] Fix Schematicannon rail placement crash --- .../foundation/utility/BlockHelper.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java b/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java index a0e3049e6..92a1c50fb 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/BlockHelper.java @@ -11,6 +11,7 @@ import com.simibubi.create.content.contraptions.components.actors.SeatBlock; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.core.Registry; +import net.minecraft.core.SectionPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.ServerLevel; @@ -194,17 +195,19 @@ public class BlockHelper { } private static void placeRailWithoutUpdate(Level world, BlockState state, BlockPos target) { - int i = target.getX() & 15; - int j = target.getY(); - int k = target.getZ() & 15; LevelChunk chunk = world.getChunkAt(target); - LevelChunkSection chunksection = chunk.getSections()[j >> 4]; + int idx = chunk.getSectionIndex(target.getY()); + LevelChunkSection chunksection = chunk.getSection(idx); if (chunksection == null) { - chunksection = new LevelChunkSection(j >> 4 << 4, world.registryAccess() - .registryOrThrow(Registry.BIOME_REGISTRY)); - chunk.getSections()[j >> 4] = chunksection; + chunksection = new LevelChunkSection(chunk.getSectionYFromSectionIndex(idx), + world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY)); + chunk.getSections()[idx] = chunksection; } - BlockState old = chunksection.setBlockState(i, j & 15, k, state); + BlockState old = chunksection.setBlockState( + SectionPos.sectionRelative(target.getX()), + SectionPos.sectionRelative(target.getY()), + SectionPos.sectionRelative(target.getZ()), + state); chunk.setUnsaved(true); world.markAndNotifyBlock(target, chunk, old, state, 82, 512);