Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@
import dev.ryanhcode.sable.util.BoundedBitVolume3i;
import dev.ryanhcode.sable.util.LevelAccelerator;
import it.unimi.dsi.fastutil.Pair;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.tags.TagKey;
import net.minecraft.world.Clearable;
import net.minecraft.world.RandomizableContainer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.decoration.HangingEntity;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DiodeBlock;
import net.minecraft.world.level.block.TorchBlock;
import net.minecraft.world.level.block.BellBlock;
import net.minecraft.world.level.block.SignBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.Rotation;
Expand Down Expand Up @@ -65,7 +72,7 @@ public class SubLevelAssemblyHelper {
* @param blocks all blocks that will be assembled into the sub-level
* @param bounds the bounds in which {@link TrackingPoint tracking points} and retained entities will be moved
*/
public static ServerSubLevel assembleBlocks(final ServerLevel level, final BlockPos anchor, final Iterable<BlockPos> blocks, final BoundingBox3ic bounds) {
public static ServerSubLevel assembleBlocks(final ServerLevel level, final BlockPos anchor, Iterable<BlockPos> blocks, final BoundingBox3ic bounds) {
final ServerSubLevelContainer container = SubLevelContainer.getContainer(level);
assert container != null;

Expand All @@ -79,6 +86,33 @@ public static ServerSubLevel assembleBlocks(final ServerLevel level, final Block
pose.orientation().set(containingPose.orientation());
}

// Get Create's brittle and wrench_pickup tags.
final TagKey< Block > createBrittleTag = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("create", "brittle"));
final TagKey< Block > createWrenchPickupTag = TagKey.create(Registries.BLOCK, ResourceLocation.fromNamespaceAndPath("create", "wrench_pickup"));

final LevelAccelerator accelerator = new LevelAccelerator(level);
final ObjectArrayList<BlockPos> newBlocks = new ObjectArrayList<>();
final ObjectArrayList<BlockPos> brittleBlocks = new ObjectArrayList<>();

// Check if blocks have Create's brittle tag or the wrench_pickup tag for redstone blocks.
for (final BlockPos pos : blocks) {
final LevelChunk chunk = accelerator.getChunk(SectionPos.blockToSectionCoord(pos.getX()),
SectionPos.blockToSectionCoord(pos.getZ()));

final BlockState posState = chunk.getBlockState(pos);
final Block block = posState.getBlock();

// A bit of a dirty way of checking for affected blocks.
if (posState.is(createBrittleTag) || posState.is(createWrenchPickupTag)
|| block instanceof DiodeBlock || block instanceof TorchBlock || block instanceof SignBlock) { brittleBlocks.add(pos); continue; }
newBlocks.add(pos);
}

// Add all brittle blocks in the front of the blocks list so they are processed first.
newBlocks.addAll(0, brittleBlocks);

blocks = newBlocks;

final ServerSubLevel subLevel = (ServerSubLevel) container.allocateNewSubLevel(pose);

final LevelPlot plot = subLevel.getPlot();
Expand Down Expand Up @@ -539,4 +573,4 @@ public enum State {
}
}
}
}
}