|
29 | 29 | import com.google.common.collect.Multimap; |
30 | 30 | import com.simibubi.create.AllBlockEntityTypes; |
31 | 31 | import com.simibubi.create.AllBlocks; |
| 32 | +import com.simibubi.create.AllItems; |
32 | 33 | import com.simibubi.create.AllTags.AllContraptionTypeTags; |
33 | 34 | import com.simibubi.create.api.behaviour.interaction.MovingInteractionBehaviour; |
34 | 35 | import com.simibubi.create.api.behaviour.movement.MovementBehaviour; |
|
57 | 58 | import com.simibubi.create.content.contraptions.pulley.PulleyBlock.MagnetBlock; |
58 | 59 | import com.simibubi.create.content.contraptions.pulley.PulleyBlock.RopeBlock; |
59 | 60 | 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; |
60 | 63 | 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; |
61 | 66 | import com.simibubi.create.content.kinetics.base.BlockBreakingMovementBehaviour; |
62 | 67 | import com.simibubi.create.content.kinetics.base.IRotate; |
63 | 68 | import com.simibubi.create.content.kinetics.base.KineticBlockEntity; |
64 | 69 | import com.simibubi.create.content.kinetics.belt.BeltBlock; |
| 70 | +import com.simibubi.create.content.kinetics.belt.BeltBlockEntity; |
65 | 71 | import com.simibubi.create.content.kinetics.chainConveyor.ChainConveyorBlockEntity; |
| 72 | +import com.simibubi.create.content.kinetics.crafter.MechanicalCrafterBlockEntity; |
66 | 73 | import com.simibubi.create.content.kinetics.gantry.GantryShaftBlock; |
67 | 74 | import com.simibubi.create.content.kinetics.simpleRelays.ShaftBlock; |
68 | 75 | import com.simibubi.create.content.kinetics.steamEngine.PoweredShaftBlockEntity; |
69 | 76 | import com.simibubi.create.content.logistics.crate.CreativeCrateBlockEntity; |
70 | 77 | import com.simibubi.create.content.logistics.factoryBoard.FactoryPanelBlockEntity; |
| 78 | +import com.simibubi.create.content.logistics.vault.ItemVaultBlockEntity; |
71 | 79 | import com.simibubi.create.content.redstone.contact.RedstoneContactBlock; |
| 80 | +import com.simibubi.create.content.schematics.cannon.SchematicannonBlockEntity; |
72 | 81 | import com.simibubi.create.content.trains.bogey.AbstractBogeyBlock; |
73 | 82 | import com.simibubi.create.foundation.blockEntity.IMultiBlockEntityContainer; |
74 | 83 | 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; |
75 | 86 | import com.simibubi.create.foundation.utility.BlockHelper; |
76 | 87 | import com.simibubi.create.infrastructure.config.AllConfigs; |
77 | 88 |
|
|
94 | 105 | import net.minecraft.network.protocol.game.DebugPackets; |
95 | 106 | import net.minecraft.resources.ResourceLocation; |
96 | 107 | import net.minecraft.server.level.ServerLevel; |
| 108 | +import net.minecraft.world.Container; |
| 109 | +import net.minecraft.world.Containers; |
97 | 110 | import net.minecraft.world.entity.Entity; |
98 | 111 | import net.minecraft.world.entity.ai.village.poi.PoiTypes; |
99 | 112 | import net.minecraft.world.item.ItemStack; |
|
108 | 121 | import net.minecraft.world.level.block.PressurePlateBlock; |
109 | 122 | import net.minecraft.world.level.block.Rotation; |
110 | 123 | import net.minecraft.world.level.block.SimpleWaterloggedBlock; |
| 124 | +import net.minecraft.world.level.block.ShulkerBoxBlock; |
111 | 125 | import net.minecraft.world.level.block.entity.BlockEntity; |
| 126 | +import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity; |
112 | 127 | import net.minecraft.world.level.block.state.BlockState; |
113 | 128 | import net.minecraft.world.level.block.state.properties.BlockStateProperties; |
114 | 129 | import net.minecraft.world.level.block.state.properties.ChestType; |
@@ -1168,6 +1183,67 @@ public void addBlocksToWorld(Level world, StructureTransform transform) { |
1168 | 1183 | if (targetPos.getY() == world.getMinBuildHeight()) |
1169 | 1184 | targetPos = targetPos.above(); |
1170 | 1185 | 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 | + } |
1171 | 1247 | Block.dropResources(state, world, targetPos, null); |
1172 | 1248 | continue; |
1173 | 1249 | } |
|
0 commit comments