Skip to content

Commit 4a4a004

Browse files
committed
you should drop your stuff before poping!
1 parent 1c4ad64 commit 4a4a004

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

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

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222

2323
import javax.annotation.Nullable;
2424

25+
import com.simibubi.create.AllItems;
26+
import com.simibubi.create.content.decoration.bracket.BracketedBlockEntityBehaviour;
27+
import com.simibubi.create.content.equipment.toolbox.ToolboxBlockEntity;
28+
29+
import com.simibubi.create.content.fluids.drain.ItemDrainBlockEntity;
30+
import com.simibubi.create.content.kinetics.belt.BeltBlockEntity;
31+
import com.simibubi.create.content.kinetics.crafter.MechanicalCrafterBlock;
32+
import com.simibubi.create.content.kinetics.crafter.MechanicalCrafterBlockEntity;
33+
import com.simibubi.create.content.schematics.cannon.SchematicannonBlockEntity;
34+
35+
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
36+
2537
import org.apache.commons.lang3.tuple.MutablePair;
2638
import org.apache.commons.lang3.tuple.Pair;
2739

@@ -57,6 +69,7 @@
5769
import com.simibubi.create.content.contraptions.pulley.PulleyBlock.MagnetBlock;
5870
import com.simibubi.create.content.contraptions.pulley.PulleyBlock.RopeBlock;
5971
import com.simibubi.create.content.contraptions.pulley.PulleyBlockEntity;
72+
import com.simibubi.create.content.decoration.placard.PlacardBlockEntity;
6073
import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorBlock;
6174
import com.simibubi.create.content.kinetics.base.BlockBreakingMovementBehaviour;
6275
import com.simibubi.create.content.kinetics.base.IRotate;
@@ -68,10 +81,13 @@
6881
import com.simibubi.create.content.kinetics.steamEngine.PoweredShaftBlockEntity;
6982
import com.simibubi.create.content.logistics.crate.CreativeCrateBlockEntity;
7083
import com.simibubi.create.content.logistics.factoryBoard.FactoryPanelBlockEntity;
84+
import com.simibubi.create.content.logistics.vault.ItemVaultBlockEntity;
7185
import com.simibubi.create.content.redstone.contact.RedstoneContactBlock;
7286
import com.simibubi.create.content.trains.bogey.AbstractBogeyBlock;
7387
import com.simibubi.create.foundation.blockEntity.IMultiBlockEntityContainer;
7488
import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringBehaviour;
89+
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
90+
import com.simibubi.create.foundation.item.ItemHelper;
7591
import com.simibubi.create.foundation.utility.BlockHelper;
7692
import com.simibubi.create.infrastructure.config.AllConfigs;
7793

@@ -94,6 +110,8 @@
94110
import net.minecraft.network.protocol.game.DebugPackets;
95111
import net.minecraft.resources.ResourceLocation;
96112
import net.minecraft.server.level.ServerLevel;
113+
import net.minecraft.world.Container;
114+
import net.minecraft.world.Containers;
97115
import net.minecraft.world.entity.Entity;
98116
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
99117
import net.minecraft.world.item.ItemStack;
@@ -1168,6 +1186,52 @@ public void addBlocksToWorld(Level world, StructureTransform transform) {
11681186
if (targetPos.getY() == world.getMinBuildHeight())
11691187
targetPos = targetPos.above();
11701188
world.levelEvent(2001, targetPos, Block.getId(state));
1189+
if(state.hasBlockEntity()){
1190+
CompoundTag tag = block.nbt();
1191+
if(tag != null) {
1192+
BlockEntity blockEntity = BlockEntity.loadStatic(targetPos, state, tag);
1193+
if (blockEntity instanceof ToolboxBlockEntity toolbox){
1194+
continue;
1195+
} else if (blockEntity instanceof ShulkerBoxBlockEntity shulkerBox) {
1196+
continue;
1197+
}
1198+
else if (blockEntity instanceof Container container)
1199+
Containers.dropContents(world, targetPos, container);
1200+
else if (blockEntity instanceof ItemVaultBlockEntity vault)
1201+
ItemHelper.dropContents(world, targetPos, vault.getInventoryOfBlock());
1202+
else if (blockEntity instanceof PlacardBlockEntity placard)
1203+
Block.popResource(world, targetPos, placard.getHeldItem());
1204+
else if (blockEntity instanceof SchematicannonBlockEntity schematicannon)
1205+
ItemHelper.dropContents(world, targetPos, schematicannon.inventory);
1206+
else if (blockEntity instanceof ItemDrainBlockEntity itemDrain){
1207+
ItemStack heldItemStack = itemDrain.getHeldItemStack();
1208+
if (!heldItemStack.isEmpty())
1209+
Containers.dropItemStack(world, targetPos.getX(), targetPos.getY(), targetPos.getZ(), heldItemStack);
1210+
}
1211+
else if (blockEntity instanceof MechanicalCrafterBlockEntity mechanicalCrafter){
1212+
if (mechanicalCrafter.isCovered())
1213+
Block.popResource(world, targetPos, AllItems.CRAFTER_SLOT_COVER.asStack());
1214+
ItemStack itemStack = mechanicalCrafter.getInventory().getItem(0);
1215+
if (!itemStack.isEmpty())
1216+
Containers.dropItemStack(world, targetPos.getX(), targetPos.getY(), targetPos.getZ(), itemStack);
1217+
}
1218+
else if (blockEntity instanceof SmartBlockEntity sbe){
1219+
sbe.setLevel(world);
1220+
sbe.destroy();
1221+
if (sbe instanceof BeltBlockEntity belt) {
1222+
if (belt.hasPulley())
1223+
Block.popResource(world, targetPos, AllBlocks.SHAFT.asStack());
1224+
continue;
1225+
}
1226+
BracketedBlockEntityBehaviour behaviour = sbe.getBehaviour(BracketedBlockEntityBehaviour.TYPE);
1227+
if (behaviour.isBracketPresent()){
1228+
BlockState bracket = behaviour.getBracket();
1229+
if (bracket != null)
1230+
Block.popResource(world, targetPos, new ItemStack(bracket.getBlock()));
1231+
}
1232+
}
1233+
}
1234+
}
11711235
Block.dropResources(state, world, targetPos, null);
11721236
continue;
11731237
}

src/main/java/com/simibubi/create/content/kinetics/crafter/MechanicalCrafterBlockEntity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,10 @@ protected DirectBeltInputBehaviour getTargetingBelt() {
396396
return BlockEntityBehaviour.get(level, targetPos, DirectBeltInputBehaviour.TYPE);
397397
}
398398

399+
public boolean isCovered(){
400+
return covered;
401+
}
402+
399403
public void tryInsert() {
400404
if (!inserting.hasInventory() && !isTargetingBelt()) {
401405
ejectWholeGrid();

0 commit comments

Comments
 (0)