Skip to content

Commit 88fc285

Browse files
committed
give me all your items! MKII
1 parent 2ed6b2b commit 88fc285

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

src/main/java/com/simibubi/create/content/contraptions/Contraption.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,8 @@ public void addBlocksToWorld(Level world, StructureTransform transform) {
11441144

11451145
translateMultiblockControllers(transform);
11461146

1147+
SingleBlockServerLevel popChamber = null;
1148+
11471149
for (boolean nonBrittles : Iterate.trueAndFalse) {
11481150
for (StructureBlockInfo block : blocks.values()) {
11491151
if (nonBrittles == BlockMovementChecks.isBrittle(block.state()))
@@ -1167,8 +1169,22 @@ public void addBlocksToWorld(Level world, StructureTransform transform) {
11671169
.isEmpty())) {
11681170
if (targetPos.getY() == world.getMinBuildHeight())
11691171
targetPos = targetPos.above();
1172+
1173+
if(popChamber == null && world instanceof ServerLevel serverWorld)
1174+
popChamber = new SingleBlockServerLevel(serverWorld);
1175+
1176+
if(popChamber != null){
1177+
popChamber.setBlock(targetPos, state, Block.UPDATE_NONE);
1178+
BlockEntity be = popChamber.getBlockEntity(targetPos);
1179+
if (be != null) {
1180+
CompoundTag tag = block.nbt();
1181+
tag = NBTProcessors.process(state, be, tag, false);
1182+
if (tag != null)
1183+
be.load(tag);
1184+
}
1185+
popChamber.destroyBlock(targetPos, true);
1186+
}
11701187
world.levelEvent(2001, targetPos, Block.getId(state));
1171-
Block.dropResources(state, world, targetPos, null);
11721188
continue;
11731189
}
11741190
if (state.getBlock() instanceof SimpleWaterloggedBlock
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.simibubi.create.content.contraptions;
2+
3+
import javax.annotation.Nullable;
4+
5+
import net.createmod.catnip.levelWrappers.WrappedServerLevel;
6+
import net.minecraft.core.BlockPos;
7+
import net.minecraft.server.level.ServerLevel;
8+
import net.minecraft.world.entity.Entity;
9+
import net.minecraft.world.item.ItemStack;
10+
import net.minecraft.world.level.block.Block;
11+
import net.minecraft.world.level.block.Blocks;
12+
import net.minecraft.world.level.block.EntityBlock;
13+
import net.minecraft.world.level.block.entity.BlockEntity;
14+
import net.minecraft.world.level.block.state.BlockState;
15+
16+
public class SingleBlockServerLevel extends WrappedServerLevel {
17+
18+
public BlockState blockState;
19+
public @Nullable BlockEntity blockEntity;
20+
21+
public SingleBlockServerLevel(ServerLevel level) {
22+
super(level);
23+
blockState = Blocks.AIR.defaultBlockState();
24+
blockEntity = null;
25+
}
26+
27+
@Override
28+
public boolean setBlock(BlockPos pos, BlockState newState, int flags) {
29+
blockState.onRemove(this, pos, newState, (flags & 64) != 0);
30+
blockState = newState;
31+
blockEntity = null;
32+
return true;
33+
}
34+
35+
@Override
36+
public BlockState getBlockState(BlockPos pos) {
37+
return blockState;
38+
}
39+
40+
@Nullable
41+
public BlockEntity getBlockEntity(BlockPos pos) {
42+
if (blockState.hasBlockEntity() && blockEntity == null)
43+
blockEntity = ((EntityBlock) blockState.getBlock()).newBlockEntity(pos, blockState);
44+
return blockEntity;
45+
}
46+
47+
@Override
48+
public boolean destroyBlock(BlockPos pos, boolean dropBlock, @Nullable Entity entity, int recursionLeft){
49+
if (blockState.isAir())
50+
return false;
51+
if (dropBlock)
52+
Block.dropResources(blockState, this, pos, blockEntity, entity, ItemStack.EMPTY);
53+
setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_NONE);
54+
return true;
55+
}
56+
}

0 commit comments

Comments
 (0)