|
21 | 21 |
|
22 | 22 | import com.google.common.collect.Sets; |
23 | 23 | import com.sk89q.jnbt.CompoundTag; |
| 24 | +import com.sk89q.jnbt.CompoundTagBuilder; |
| 25 | +import com.sk89q.jnbt.IntTag; |
| 26 | +import com.sk89q.jnbt.StringTag; |
24 | 27 | import com.sk89q.worldedit.EditSession; |
25 | 28 | import com.sk89q.worldedit.WorldEditException; |
26 | 29 | import com.sk89q.worldedit.blocks.BaseItemStack; |
|
57 | 60 | import org.spongepowered.api.ResourceKey; |
58 | 61 | import org.spongepowered.api.Server; |
59 | 62 | import org.spongepowered.api.Sponge; |
| 63 | +import org.spongepowered.api.block.entity.BlockEntity; |
60 | 64 | import org.spongepowered.api.block.entity.BlockEntityArchetype; |
61 | 65 | import org.spongepowered.api.block.entity.BlockEntityType; |
62 | 66 | import org.spongepowered.api.entity.EntityArchetype; |
@@ -152,11 +156,25 @@ public BlockState getBlock(BlockVector3 position) { |
152 | 156 |
|
153 | 157 | @Override |
154 | 158 | public BaseBlock getFullBlock(BlockVector3 position) { |
155 | | - CompoundTag entity = getWorld() |
156 | | - .blockEntity(position.getX(), position.getY(), position.getZ()) |
157 | | - .map(e -> NbtAdapter.adaptToWorldEdit(e.createArchetype().blockEntityData())) |
158 | | - .orElse(null); |
159 | | - return getBlock(position).toBaseBlock(entity); |
| 159 | + BlockEntity blockEntity = getWorld().blockEntity( |
| 160 | + position.getX(), position.getY(), position.getZ() |
| 161 | + ).orElse(null); |
| 162 | + CompoundTag blockEntityData = null; |
| 163 | + if (blockEntity != null) { |
| 164 | + BlockEntityArchetype blockEntityArchetype = blockEntity.createArchetype(); |
| 165 | + BlockEntityType blockEntityType = blockEntityArchetype.blockEntityType(); |
| 166 | + ResourceKey blockEntityId = blockEntityType.key(RegistryTypes.BLOCK_ENTITY_TYPE); |
| 167 | + blockEntityData = NbtAdapter.adaptToWorldEdit(blockEntityArchetype.blockEntityData()); |
| 168 | + |
| 169 | + // Add ID and position since Sponge's #blockEntityData does not save metadata |
| 170 | + CompoundTagBuilder fullBlockEntityDataBuilder = blockEntityData.createBuilder(); |
| 171 | + fullBlockEntityDataBuilder.put("id", new StringTag(blockEntityId.formatted())); |
| 172 | + fullBlockEntityDataBuilder.put("x", new IntTag(position.getX())); |
| 173 | + fullBlockEntityDataBuilder.put("y", new IntTag(position.getY())); |
| 174 | + fullBlockEntityDataBuilder.put("z", new IntTag(position.getZ())); |
| 175 | + blockEntityData = fullBlockEntityDataBuilder.build(); |
| 176 | + } |
| 177 | + return getBlock(position).toBaseBlock(blockEntityData); |
160 | 178 | } |
161 | 179 |
|
162 | 180 | @Override |
@@ -195,7 +213,7 @@ public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B |
195 | 213 | BaseBlock baseBlock = (BaseBlock) block; |
196 | 214 | BlockEntityArchetype.builder() |
197 | 215 | .blockEntity((BlockEntityType) |
198 | | - world.engine().registry(RegistryTypes.BLOCK_ENTITY_TYPE) |
| 216 | + Sponge.game().registry(RegistryTypes.BLOCK_ENTITY_TYPE) |
199 | 217 | .value(ResourceKey.resolve(baseBlock.getNbtId())) |
200 | 218 | ) |
201 | 219 | .blockEntityData(NbtAdapter.adaptFromWorldEdit(baseBlock.getNbtData())) |
|
0 commit comments