|
22 | 22 |
|
23 | 23 | import javax.annotation.Nullable; |
24 | 24 |
|
| 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 | + |
25 | 37 | import org.apache.commons.lang3.tuple.MutablePair; |
26 | 38 | import org.apache.commons.lang3.tuple.Pair; |
27 | 39 |
|
|
57 | 69 | import com.simibubi.create.content.contraptions.pulley.PulleyBlock.MagnetBlock; |
58 | 70 | import com.simibubi.create.content.contraptions.pulley.PulleyBlock.RopeBlock; |
59 | 71 | import com.simibubi.create.content.contraptions.pulley.PulleyBlockEntity; |
| 72 | +import com.simibubi.create.content.decoration.placard.PlacardBlockEntity; |
60 | 73 | import com.simibubi.create.content.decoration.slidingDoor.SlidingDoorBlock; |
61 | 74 | import com.simibubi.create.content.kinetics.base.BlockBreakingMovementBehaviour; |
62 | 75 | import com.simibubi.create.content.kinetics.base.IRotate; |
|
68 | 81 | import com.simibubi.create.content.kinetics.steamEngine.PoweredShaftBlockEntity; |
69 | 82 | import com.simibubi.create.content.logistics.crate.CreativeCrateBlockEntity; |
70 | 83 | import com.simibubi.create.content.logistics.factoryBoard.FactoryPanelBlockEntity; |
| 84 | +import com.simibubi.create.content.logistics.vault.ItemVaultBlockEntity; |
71 | 85 | import com.simibubi.create.content.redstone.contact.RedstoneContactBlock; |
72 | 86 | import com.simibubi.create.content.trains.bogey.AbstractBogeyBlock; |
73 | 87 | import com.simibubi.create.foundation.blockEntity.IMultiBlockEntityContainer; |
74 | 88 | 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; |
75 | 91 | import com.simibubi.create.foundation.utility.BlockHelper; |
76 | 92 | import com.simibubi.create.infrastructure.config.AllConfigs; |
77 | 93 |
|
|
94 | 110 | import net.minecraft.network.protocol.game.DebugPackets; |
95 | 111 | import net.minecraft.resources.ResourceLocation; |
96 | 112 | import net.minecraft.server.level.ServerLevel; |
| 113 | +import net.minecraft.world.Container; |
| 114 | +import net.minecraft.world.Containers; |
97 | 115 | import net.minecraft.world.entity.Entity; |
98 | 116 | import net.minecraft.world.entity.ai.village.poi.PoiTypes; |
99 | 117 | import net.minecraft.world.item.ItemStack; |
@@ -1168,6 +1186,52 @@ public void addBlocksToWorld(Level world, StructureTransform transform) { |
1168 | 1186 | if (targetPos.getY() == world.getMinBuildHeight()) |
1169 | 1187 | targetPos = targetPos.above(); |
1170 | 1188 | 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 | + } |
1171 | 1235 | Block.dropResources(state, world, targetPos, null); |
1172 | 1236 | continue; |
1173 | 1237 | } |
|
0 commit comments