1111import net .minecraft .util .EnumFacing ;
1212import net .minecraft .util .ResourceLocation ;
1313import net .minecraft .util .math .BlockPos ;
14+ import net .minecraft .util .math .Vec3i ;
1415import net .minecraft .util .text .ITextComponent ;
1516import net .minecraft .util .text .TextComponentString ;
1617import org .dimdev .ddutils .schem .Schematic ;
@@ -105,14 +106,14 @@ public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId,
105106 }
106107 }
107108
108- NBTTagList tileEntitiesNBT = (NBTTagList ) nbt .getTag ("TileEntities" );
109+ List <Vec3i > tileEntityPositions = new ArrayList <>();
110+
111+ NBTTagList tileEntitiesNBT = nbt .getTagList ("TileEntities" , 1 ); // 1 = NBTTagCompound
109112 for (int i = 0 ; i < tileEntitiesNBT .tagCount (); i ++) {
110113 NBTTagCompound tileEntityNBT = tileEntitiesNBT .getCompoundTagAt (i );
111114 switch (tileEntityNBT .getString ("id" )) {
112115 case "TileEntityDimDoor" :
113116 case "TileEntityRift" :
114- case "TileEntityChest" :
115- case "TileEntityDispenser" :
116117 continue ; // remove all Rifts and containers from the TileEntities. These will get added back later
117118 case "Sign" :
118119 tileEntityNBT .setString ("Text1" , ITextComponent .Serializer .componentToJson (new TextComponentString (tileEntityNBT .getString ("Text1" ))));
@@ -124,6 +125,7 @@ public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId,
124125 break ;
125126 }
126127 tileEntityNBT .setString ("id" , translateId (tileEntityNBT .getString ("id" )).toString ());
128+ tileEntityPositions .add (new Vec3i (tileEntityNBT .getInteger ("x" ), tileEntityNBT .getInteger ("y" ), tileEntityNBT .getInteger ("z" )));
127129 schematic .tileEntities .add (tileEntityNBT );
128130 }
129131
@@ -157,17 +159,6 @@ public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId,
157159 goldBlocks ++;
158160 } else if (block .equals (Blocks .IRON_BLOCK )) {
159161 ironBlocks ++;
160- } else if (block .equals (Blocks .CHEST )) {
161- chests ++;
162- TileEntityChest chest = new TileEntityChest ();
163- chest .setPos (new BlockPos (x , y , z ));
164- schematic .tileEntities .add (chest .serializeNBT ());
165- } else if (block .equals (Blocks .DISPENSER )) {
166- dispensers ++;
167- // TODO: Are some dispensers achtually already pre-filled? And if so, what should I actually be doing here?
168- TileEntityDispenser dispenser = new TileEntityDispenser ();
169- dispenser .setPos (new BlockPos (x , y , z ));
170- schematic .tileEntities .add (dispenser .serializeNBT ());
171162 } else if (block .equals (Blocks .END_PORTAL_FRAME )) {
172163 monoliths ++;
173164 // I think it's safe to assume that air is present
@@ -243,17 +234,24 @@ public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId,
243234
244235 schematic .tileEntities .add (rift .serializeNBT ());
245236 }
246- }
247-
248- if (blockState .getBlock ().equals (Blocks .END_PORTAL_FRAME )) {
237+ } else if (blockState .getBlock ().equals (Blocks .END_PORTAL_FRAME )) {
249238 monoliths ++;
250239 // I think it's safe to assume that air is present
251240 blockInt = schematic .palette .indexOf (Blocks .AIR .getDefaultState ());
252241 EntityMonolith monolith = new EntityMonolith (null );
253242 EnumFacing facing = blockState .getValue (BlockEndPortalFrame .FACING );
254243 monolith .setLocationAndAngles (x + 0.5d , y , z + 0.5d , facing .getHorizontalAngle (), 0 );
255244 schematic .entities .add (monolith .serializeNBT ());
245+ } else if (blockState .getBlock ().hasTileEntity (blockState ) && !tileEntityPositions .contains (new Vec3i (x , y , z ))) {
246+ TileEntity tileEntity = block .createTileEntity (null , blockState );
247+ tileEntity .setPos (new BlockPos (x , y , z ));
248+ tileEntitiesNBT .appendTag (tileEntity .serializeNBT ());
249+ DimDoors .log .info ("Adding missing tile entity at " + new Vec3i (x , y , z ) + " (state = " + blockState + ")" );
256250 }
251+
252+ if (block .equals (Blocks .CHEST )) chests ++;
253+ if (block .equals (Blocks .DISPENSER )) dispensers ++;
254+
257255 } else { // if this is ancient fabric
258256 blockInt = schematic .palette .indexOf (baseState );
259257 }
0 commit comments