Skip to content

Second Approach to Fix #5420 #8907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: mc1.20.1/dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -1144,6 +1144,8 @@ public void addBlocksToWorld(Level world, StructureTransform transform) {

translateMultiblockControllers(transform);

SingleBlockServerLevel popChamber = null;

for (boolean nonBrittles : Iterate.trueAndFalse) {
for (StructureBlockInfo block : blocks.values()) {
if (nonBrittles == BlockMovementChecks.isBrittle(block.state()))
Expand All @@ -1167,8 +1169,22 @@ public void addBlocksToWorld(Level world, StructureTransform transform) {
.isEmpty())) {
if (targetPos.getY() == world.getMinBuildHeight())
targetPos = targetPos.above();

if(popChamber == null && world instanceof ServerLevel serverWorld)
popChamber = new SingleBlockServerLevel(serverWorld);

if(popChamber != null){
popChamber.setBlock(targetPos, state, Block.UPDATE_NONE);
BlockEntity be = popChamber.getBlockEntity(targetPos);
if (be != null) {
CompoundTag tag = block.nbt();
tag = NBTProcessors.process(state, be, tag, false);
if (tag != null)
be.load(tag);
}
popChamber.destroyBlock(targetPos, true);
}
world.levelEvent(2001, targetPos, Block.getId(state));
Block.dropResources(state, world, targetPos, null);
continue;
}
if (state.getBlock() instanceof SimpleWaterloggedBlock
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.simibubi.create.content.contraptions;

import javax.annotation.Nullable;

import net.createmod.catnip.levelWrappers.WrappedServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;

public class SingleBlockServerLevel extends WrappedServerLevel {

public BlockState blockState;
public @Nullable BlockEntity blockEntity;

public SingleBlockServerLevel(ServerLevel level) {
super(level);
blockState = Blocks.AIR.defaultBlockState();
blockEntity = null;
}

@Override
public boolean setBlock(BlockPos pos, BlockState newState, int flags) {
blockState.onRemove(this, pos, newState, (flags & 64) != 0);
blockState = newState;
blockEntity = null;
return true;
}

@Override
public BlockState getBlockState(BlockPos pos) {
return blockState;
}

@Nullable
public BlockEntity getBlockEntity(BlockPos pos) {
if (blockState.hasBlockEntity() && blockEntity == null)
blockEntity = ((EntityBlock) blockState.getBlock()).newBlockEntity(pos, blockState);
return blockEntity;
}

@Override
public boolean destroyBlock(BlockPos pos, boolean dropBlock, @Nullable Entity entity, int recursionLeft){
if (blockState.isAir())
return false;
if (dropBlock)
Block.dropResources(blockState, this, pos, blockEntity, entity, ItemStack.EMPTY);
setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_NONE);
return true;
}
}