Skip to content

Commit f50f4cd

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

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

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

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.common.collect.Multimap;
3030
import com.simibubi.create.AllBlockEntityTypes;
3131
import com.simibubi.create.AllBlocks;
32+
import com.simibubi.create.AllItems;
3233
import com.simibubi.create.AllTags.AllContraptionTypeTags;
3334
import com.simibubi.create.api.behaviour.interaction.MovingInteractionBehaviour;
3435
import com.simibubi.create.api.behaviour.movement.MovementBehaviour;
@@ -57,21 +58,31 @@
5758
import com.simibubi.create.content.contraptions.pulley.PulleyBlock.MagnetBlock;
5859
import com.simibubi.create.content.contraptions.pulley.PulleyBlock.RopeBlock;
5960
import com.simibubi.create.content.contraptions.pulley.PulleyBlockEntity;
61+
import com.simibubi.create.content.decoration.bracket.BracketedBlockEntityBehaviour;
62+
import com.simibubi.create.content.decoration.placard.PlacardBlockEntity;
6063
import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorBlock;
64+
import com.simibubi.create.content.equipment.toolbox.ToolboxBlockEntity;
65+
import com.simibubi.create.content.fluids.drain.ItemDrainBlockEntity;
6166
import com.simibubi.create.content.kinetics.base.BlockBreakingMovementBehaviour;
6267
import com.simibubi.create.content.kinetics.base.IRotate;
6368
import com.simibubi.create.content.kinetics.base.KineticBlockEntity;
6469
import com.simibubi.create.content.kinetics.belt.BeltBlock;
70+
import com.simibubi.create.content.kinetics.belt.BeltBlockEntity;
6571
import com.simibubi.create.content.kinetics.chainConveyor.ChainConveyorBlockEntity;
72+
import com.simibubi.create.content.kinetics.crafter.MechanicalCrafterBlockEntity;
6673
import com.simibubi.create.content.kinetics.gantry.GantryShaftBlock;
6774
import com.simibubi.create.content.kinetics.simpleRelays.ShaftBlock;
6875
import com.simibubi.create.content.kinetics.steamEngine.PoweredShaftBlockEntity;
6976
import com.simibubi.create.content.logistics.crate.CreativeCrateBlockEntity;
7077
import com.simibubi.create.content.logistics.factoryBoard.FactoryPanelBlockEntity;
78+
import com.simibubi.create.content.logistics.vault.ItemVaultBlockEntity;
7179
import com.simibubi.create.content.redstone.contact.RedstoneContactBlock;
80+
import com.simibubi.create.content.schematics.cannon.SchematicannonBlockEntity;
7281
import com.simibubi.create.content.trains.bogey.AbstractBogeyBlock;
7382
import com.simibubi.create.foundation.blockEntity.IMultiBlockEntityContainer;
7483
import com.simibubi.create.foundation.blockEntity.behaviour.filtering.FilteringBehaviour;
84+
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
85+
import com.simibubi.create.foundation.item.ItemHelper;
7586
import com.simibubi.create.foundation.utility.BlockHelper;
7687
import com.simibubi.create.infrastructure.config.AllConfigs;
7788

@@ -94,6 +105,8 @@
94105
import net.minecraft.network.protocol.game.DebugPackets;
95106
import net.minecraft.resources.ResourceLocation;
96107
import net.minecraft.server.level.ServerLevel;
108+
import net.minecraft.world.Container;
109+
import net.minecraft.world.Containers;
97110
import net.minecraft.world.entity.Entity;
98111
import net.minecraft.world.entity.ai.village.poi.PoiTypes;
99112
import net.minecraft.world.item.ItemStack;
@@ -108,7 +121,9 @@
108121
import net.minecraft.world.level.block.PressurePlateBlock;
109122
import net.minecraft.world.level.block.Rotation;
110123
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
124+
import net.minecraft.world.level.block.ShulkerBoxBlock;
111125
import net.minecraft.world.level.block.entity.BlockEntity;
126+
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
112127
import net.minecraft.world.level.block.state.BlockState;
113128
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
114129
import net.minecraft.world.level.block.state.properties.ChestType;
@@ -1168,6 +1183,67 @@ public void addBlocksToWorld(Level world, StructureTransform transform) {
11681183
if (targetPos.getY() == world.getMinBuildHeight())
11691184
targetPos = targetPos.above();
11701185
world.levelEvent(2001, targetPos, Block.getId(state));
1186+
if(state.hasBlockEntity()){
1187+
CompoundTag tag = block.nbt();
1188+
if(tag != null) {
1189+
BlockEntity blockEntity = BlockEntity.loadStatic(targetPos, state, tag);
1190+
if (blockEntity instanceof ToolboxBlockEntity toolbox){
1191+
ItemStack itemstack = new ItemStack(state.getBlock().asItem());
1192+
CompoundTag item_tag = itemstack.getOrCreateTag();
1193+
item_tag.put("Inventory", toolbox.getInventoryOfBlock().serializeNBT());
1194+
if(toolbox.isFullyInitialized())
1195+
item_tag.putUUID("UniqueId", toolbox.getUniqueId());
1196+
if(toolbox.hasCustomName())
1197+
itemstack.setHoverName(toolbox.getCustomName());
1198+
Block.popResource(world, targetPos, itemstack);
1199+
continue;
1200+
} else if (blockEntity instanceof ShulkerBoxBlockEntity shulkerBox) {
1201+
if (state.getBlock() instanceof ShulkerBoxBlock shulkerblock){
1202+
ItemStack itemstack = ShulkerBoxBlock.getColoredItemStack(shulkerblock.getColor());
1203+
shulkerBox.saveToItem(itemstack);
1204+
if (shulkerBox.hasCustomName())
1205+
itemstack.setHoverName(shulkerBox.getCustomName());
1206+
Block.popResource(world, targetPos, itemstack);
1207+
continue;
1208+
}
1209+
}
1210+
else if (blockEntity instanceof Container container)
1211+
Containers.dropContents(world, targetPos, container);
1212+
else if (blockEntity instanceof ItemVaultBlockEntity vault)
1213+
ItemHelper.dropContents(world, targetPos, vault.getInventoryOfBlock());
1214+
else if (blockEntity instanceof PlacardBlockEntity placard)
1215+
Block.popResource(world, targetPos, placard.getHeldItem());
1216+
else if (blockEntity instanceof SchematicannonBlockEntity schematicannon)
1217+
ItemHelper.dropContents(world, targetPos, schematicannon.inventory);
1218+
else if (blockEntity instanceof ItemDrainBlockEntity itemDrain){
1219+
ItemStack heldItemStack = itemDrain.getHeldItemStack();
1220+
if (!heldItemStack.isEmpty())
1221+
Containers.dropItemStack(world, targetPos.getX(), targetPos.getY(), targetPos.getZ(), heldItemStack);
1222+
}
1223+
else if (blockEntity instanceof MechanicalCrafterBlockEntity mechanicalCrafter){
1224+
if (mechanicalCrafter.isCovered())
1225+
Block.popResource(world, targetPos, AllItems.CRAFTER_SLOT_COVER.asStack());
1226+
ItemStack itemStack = mechanicalCrafter.getInventory().getItem(0);
1227+
if (!itemStack.isEmpty())
1228+
Containers.dropItemStack(world, targetPos.getX(), targetPos.getY(), targetPos.getZ(), itemStack);
1229+
}
1230+
else if (blockEntity instanceof SmartBlockEntity sbe){
1231+
sbe.setLevel(world);
1232+
sbe.destroy();
1233+
if (sbe instanceof BeltBlockEntity belt) {
1234+
if (belt.hasPulley())
1235+
Block.popResource(world, targetPos, AllBlocks.SHAFT.asStack());
1236+
continue;
1237+
}
1238+
BracketedBlockEntityBehaviour behaviour = sbe.getBehaviour(BracketedBlockEntityBehaviour.TYPE);
1239+
if (behaviour.isBracketPresent()){
1240+
BlockState bracket = behaviour.getBracket();
1241+
if (bracket != null)
1242+
Block.popResource(world, targetPos, new ItemStack(bracket.getBlock()));
1243+
}
1244+
}
1245+
}
1246+
}
11711247
Block.dropResources(state, world, targetPos, null);
11721248
continue;
11731249
}

src/main/java/com/simibubi/create/content/equipment/toolbox/ToolboxBlockEntity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ public void readInventory(CompoundTag compound) {
331331
inventory.deserializeNBT(compound);
332332
}
333333

334+
public ToolboxInventory getInventoryOfBlock() { return inventory; }
335+
334336
public void setUniqueId(UUID uniqueId) {
335337
this.uniqueId = uniqueId;
336338
}

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)