Revert to 1.6.4 schematics and other fixes

- Revert to 1.6.4 schematics
 - Fix iron doors being treated as wood doors
 - Fix crash when available link door has no LinkProperties
This commit is contained in:
Runemoro 2018-01-18 13:48:05 -05:00
parent c8c706bac4
commit 931b804b10
117 changed files with 61 additions and 79 deletions

View file

@ -68,13 +68,13 @@ public class PocketTemplate {
if (tile instanceof TileEntityRift) { if (tile instanceof TileEntityRift) {
DimDoors.log.info("Rift found in schematic at " + pos); DimDoors.log.info("Rift found in schematic at " + pos);
pocket.riftLocations.add(new Location(world, pos)); pocket.riftLocations.add(new Location(world, pos));
} else if (tile instanceof TileEntityChest){ } else if (tile instanceof TileEntityChest) {
DimDoors.log.info("Now populating chest."); DimDoors.log.info("Now populating chest.");
TileEntityChest chest = (TileEntityChest) tile; TileEntityChest chest = (TileEntityChest) tile;
LootTable table = world.getLootTableManager().getLootTableFromLocation(new ResourceLocation(DimDoors.MODID+":dungeon_chest")); LootTable table = world.getLootTableManager().getLootTableFromLocation(new ResourceLocation(DimDoors.MODID + ":dungeon_chest"));
LootContext ctx = new LootContext.Builder(world).build(); LootContext ctx = new LootContext.Builder(world).build();
table.fillInventory(chest, world.rand, ctx); table.fillInventory(chest, world.rand, ctx);
DimDoors.log.info("Chest should be populated now. Chest is: " + (chest.isEmpty()? "emtpy.":"filled.")); DimDoors.log.info("Chest should be populated now. Chest is: " + (chest.isEmpty() ? "emtpy." : "filled."));
} }
} }
} }

View file

@ -131,7 +131,7 @@ public class SchematicHandler {
try { try {
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream); schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
if (!schematicNBT.hasKey("Version")) { if (!schematicNBT.hasKey("Version")) {
schematic = SchematicConverter.convertSchematic(schematicNBT, template.getName(), template.getAuthor()); schematic = SchematicConverter.convertSchematic(schematicNBT, template.getId(), template.getName(), template.getAuthor());
} else { } else {
schematic = Schematic.loadFromNBT(schematicNBT); schematic = Schematic.loadFromNBT(schematicNBT);
} }

View file

@ -152,7 +152,7 @@ import java.util.Set;
// Link the pocket back // Link the pocket back
TileEntityRift thisRift = (TileEntityRift) location.getLocation().getTileEntity(); TileEntityRift thisRift = (TileEntityRift) location.getLocation().getTileEntity();
TileEntityRift riftEntity = (TileEntityRift) pocket.getEntrance().getTileEntity(); TileEntityRift riftEntity = (TileEntityRift) pocket.getEntrance().getTileEntity();
LinkProperties newLink = thisRift.getProperties().toBuilder().linksRemaining(0).build(); LinkProperties newLink = thisRift.getProperties() != null ? thisRift.getProperties().toBuilder().linksRemaining(0).build() : null;
pocket.linkPocketTo(new GlobalDestination(!noLinkBack && !riftEntity.getProperties().oneWay ? location.getLocation() : null), newLink); // TODO: linkId pocket.linkPocketTo(new GlobalDestination(!noLinkBack && !riftEntity.getProperties().oneWay ? location.getLocation() : null), newLink); // TODO: linkId
// Link the rift if necessary and teleport the entity // Link the rift if necessary and teleport the entity

View file

@ -13,7 +13,6 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentString;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import org.dimdev.ddutils.schem.Schematic; import org.dimdev.ddutils.schem.Schematic;
import org.dimdev.dimdoors.DimDoors; import org.dimdev.dimdoors.DimDoors;
import org.dimdev.dimdoors.shared.blocks.BlockFabric; import org.dimdev.dimdoors.shared.blocks.BlockFabric;
@ -32,19 +31,7 @@ import java.util.*;
*/ */
public final class SchematicConverter { public final class SchematicConverter {
private static final Map<String, IBlockState> stateMap = new HashMap<>(); public static Schematic convertSchematic(NBTTagCompound nbt, String schematicId, String name, String author) {
static {
stateMap.put("dimdoors:Dimensional Door", ModBlocks.DIMENSIONAL_DOOR.getDefaultState());
stateMap.put("dimdoors:Fabric of Reality", ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.REALITY));
stateMap.put("dimdoors:Fabric of RealityPerm", ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.ANCIENT));
stateMap.put("dimdoors:transientDoor", ModBlocks.TRANSIENT_DIMENSIONAL_DOOR.getDefaultState());
stateMap.put("dimdoors:Warp Door", ModBlocks.WARP_DIMENSIONAL_DOOR.getDefaultState());
stateMap.put("minecraft:iron_door", ModBlocks.DIMENSIONAL_DOOR.getDefaultState());
stateMap.put("minecraft:wooden_door", ModBlocks.WARP_DIMENSIONAL_DOOR.getDefaultState());
}
public static Schematic convertSchematic(NBTTagCompound nbt, String name, String author) {
Schematic schematic = new Schematic(); Schematic schematic = new Schematic();
schematic.version = 1; //already the default value schematic.version = 1; //already the default value
@ -65,58 +52,53 @@ public final class SchematicConverter {
int monoliths = 0; int monoliths = 0;
int chests = 0; int chests = 0;
byte[] blockIntArray = nbt.getByteArray("Blocks"); byte[] blockIdArray = nbt.getByteArray("Blocks");
if (nbt.hasKey("Palette")) { byte[] addId = nbt.getByteArray("AddBlocks");
NBTTagList paletteNBT = (NBTTagList) nbt.getTag("Palette"); Map<Integer, Byte> palletteMap = new HashMap<>(); // block ID -> pallette index
for (int i = 0; i < paletteNBT.tagCount(); i++) { byte currentPalletteIndex = 0;
String blockString = paletteNBT.getStringTagAt(i); for (int i = 0; i < blockIdArray.length; i++) {
IBlockState blockstate; int id;
if (i >> 1 >= addId.length) {
// Get the correct block state id = (short) (blockIdArray[i] & 0xFF);
if (blockString.startsWith("dimdoors") || blockString.equals("minecraft:iron_door") || blockString.equals("minecraft:wooden_door")) { } else if ((i & 1) == 0) {
blockstate = stateMap.get(blockString); id = (short) (((addId[i >> 1] & 0x0F) << 8) + (blockIdArray[i] & 0xFF));
} else { } else {
blockstate = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(blockString)).getDefaultState(); id = (short) (((addId[i >> 1] & 0xF0) << 4) + (blockIdArray[i] & 0xFF));
}
schematic.pallette.add(blockstate);
} }
} else { if (palletteMap.containsKey(id)) {
byte[] addId = nbt.getByteArray("AddBlocks"); blockIdArray[i] = palletteMap.get(id);
Map<Integer, Byte> palletteMap = new HashMap<>(); // block ID -> pallette index } else {
byte currentPalletteIndex = 0; IBlockState block = id <= 159 ? Block.getBlockById(id).getDefaultState() : Blocks.AIR.getDefaultState();
for (int i = 0; i < blockIntArray.length; i++) { switch (id) {
int id; case 1973:
if (i >> 1 >= addId.length) { block = ModBlocks.FABRIC.getDefaultState();
id = (short) (blockIntArray[i] & 0xFF); break;
} else if ((i & 1) == 0) { case 1975:
id = (short) (((addId[i >> 1] & 0x0F) << 8) + (blockIntArray[i] & 0xFF)); block = ModBlocks.WARP_DIMENSIONAL_DOOR.getDefaultState();
} else { break;
id = (short) (((addId[i >> 1] & 0xF0) << 4) + (blockIntArray[i] & 0xFF)); case 1970:
block = ModBlocks.DIMENSIONAL_DOOR.getDefaultState();
break;
case 1979:
block = ModBlocks.TRANSIENT_DIMENSIONAL_DOOR.getDefaultState();
break;
case 220:
block = ModBlocks.FABRIC.getDefaultState().withProperty(BlockFabric.TYPE, BlockFabric.EnumType.REALITY);
break;
case 95: // Locked chest's ID was replaced with stained glass in 1.7.2
DimDoors.log.error("Schematic contained a locked chest, which was removed in 1.7.2.");
block = Blocks.AIR.getDefaultState();
break;
} }
if (palletteMap.containsKey(id)) { if (id != 0 && block.getBlock().getRegistryName().toString().equals("minecraft:air")) {
blockIntArray[i] = palletteMap.get(id); throw new RuntimeException("Unknown ID " + id + " in schematic " + schematicId);
} else {
Block block = Block.getBlockById(id);
switch (id) {
case 1975:
block = ModBlocks.WARP_DIMENSIONAL_DOOR;
break;
case 1970:
block = ModBlocks.DIMENSIONAL_DOOR;
break;
case 1979:
block = ModBlocks.TRANSIENT_DIMENSIONAL_DOOR;
break;
}
if (id != 0 && block.getRegistryName().toString().equals("minecraft:air")) {
throw new RuntimeException("Change conversion code!");
}
schematic.pallette.add(block.getDefaultState());
palletteMap.put(id, currentPalletteIndex);
blockIntArray[i] = currentPalletteIndex;
currentPalletteIndex++;
} }
if (block.equals(Blocks.IRON_DOOR)) block = ModBlocks.DIMENSIONAL_DOOR.getDefaultState();
if (block.equals(Blocks.OAK_DOOR)) block = ModBlocks.WARP_DIMENSIONAL_DOOR.getDefaultState();
schematic.pallette.add(block);
palletteMap.put(id, currentPalletteIndex);
blockIdArray[i] = currentPalletteIndex;
currentPalletteIndex++;
} }
} }
@ -145,7 +127,7 @@ public final class SchematicConverter {
for (int x = 0; x < schematic.width; x++) { for (int x = 0; x < schematic.width; x++) {
for (int y = 0; y < schematic.height; y++) { for (int y = 0; y < schematic.height; y++) {
for (int z = 0; z < schematic.length; z++) { for (int z = 0; z < schematic.length; z++) {
int blockInt = blockIntArray[x + z * schematic.width + y * schematic.width * schematic.length]; //according to the documentation on https://github.com/SpongePowered/Schematic-Specification/blob/master/versions/schematic-1.md int blockInt = blockIdArray[x + z * schematic.width + y * schematic.width * schematic.length]; //according to the documentation on https://github.com/SpongePowered/Schematic-Specification/blob/master/versions/schematic-1.md
int metadata = dataIntArray[x + z * schematic.width + y * schematic.width * schematic.length]; //according to the documentation on https://github.com/SpongePowered/Schematic-Specification/blob/master/versions/schematic-1.md int metadata = dataIntArray[x + z * schematic.width + y * schematic.width * schematic.length]; //according to the documentation on https://github.com/SpongePowered/Schematic-Specification/blob/master/versions/schematic-1.md
IBlockState baseState = schematic.pallette.get(blockInt); //this is the default blockstate except for ancient fabric IBlockState baseState = schematic.pallette.get(blockInt); //this is the default blockstate except for ancient fabric
@ -171,7 +153,7 @@ public final class SchematicConverter {
.groups(new HashSet<>(Arrays.asList(0, 1))) .groups(new HashSet<>(Arrays.asList(0, 1)))
.linksRemaining(1).build()); .linksRemaining(1).build());
if (baseState.equals(ModBlocks.DIMENSIONAL_DOOR)) { if (baseState.getBlock().equals(ModBlocks.DIMENSIONAL_DOOR)) {
ironDoors++; ironDoors++;
rift.setDestination(AvailableLinkDestination.builder() rift.setDestination(AvailableLinkDestination.builder()
.acceptedGroups(Collections.singleton(0)) .acceptedGroups(Collections.singleton(0))
@ -198,7 +180,7 @@ public final class SchematicConverter {
if (y >= 2) { if (y >= 2) {
schematic.blockData[x][y - 1][z] = schematic.blockData[x][y - 2][z]; schematic.blockData[x][y - 1][z] = schematic.blockData[x][y - 2][z];
} else { } else {
DimDoors.log.error("Someone placed a door on a sandstone block at the bottom of a schematic. This causes problems and should be remedied. Schematic name: " + schematic.name); DimDoors.log.error("Someone placed a door on a sandstone block at the bottom of a schematic. This causes problems and should be remedied. Schematic name: " + schematicId);
} }
} else { } else {
woodDoors++; woodDoors++;
@ -217,7 +199,6 @@ public final class SchematicConverter {
schematic.tileEntities.add(rift.serializeNBT()); schematic.tileEntities.add(rift.serializeNBT());
} }
} }
if (blockState.getBlock().equals(Blocks.END_PORTAL_FRAME)) { if (blockState.getBlock().equals(Blocks.END_PORTAL_FRAME)) {
@ -237,10 +218,11 @@ public final class SchematicConverter {
} }
} }
} }
if (!nbt.getTag("Entities").hasNoTags()) throw new RuntimeException("Schematic contains entities, but those aren't implemented in the conversion code"); if (!nbt.getTag("Entities").hasNoTags())
throw new RuntimeException("Schematic contains entities, but those aren't implemented in the conversion code");
schematic.paletteMax = schematic.pallette.size() - 1; schematic.paletteMax = schematic.pallette.size() - 1;
DimDoors.log.info(schematic.name + "," + ironDoors + "," + woodDoors + "," + sandstoneDoors + "," + monoliths + "," + chests); DimDoors.log.info(schematicId + "," + schematic.name + "," + ironDoors + "," + woodDoors + "," + sandstoneDoors + "," + monoliths + "," + chests);
return schematic; return schematic;
} }

View file

@ -14,11 +14,11 @@ import java.io.InputStream;
public abstract class BaseSchematicGateway extends BaseGateway { public abstract class BaseSchematicGateway extends BaseGateway {
private Schematic schematic; private Schematic schematic;
public BaseSchematicGateway(String name) { public BaseSchematicGateway(String id) {
String schematicJarDirectory = "/assets/dimdoors/gateways/"; String schematicJarDirectory = "/assets/dimdoors/gateways/";
//Initialising the possible locations/formats for the schematic file //Initialising the possible locations/formats for the schematic file
InputStream oldVersionSchematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + name + ".schematic"); //@todo also check for other schematics InputStream oldVersionSchematicStream = DimDoors.class.getResourceAsStream(schematicJarDirectory + id + ".schematic"); //@todo also check for other schematics
//determine which location to load the schematic file from (and what format) //determine which location to load the schematic file from (and what format)
DataInputStream schematicDataStream = null; DataInputStream schematicDataStream = null;
@ -27,7 +27,7 @@ public abstract class BaseSchematicGateway extends BaseGateway {
schematicDataStream = new DataInputStream(oldVersionSchematicStream); schematicDataStream = new DataInputStream(oldVersionSchematicStream);
streamOpened = true; streamOpened = true;
} else { } else {
DimDoors.log.warn("Schematic '" + name + "' was not found in the jar or config directory, neither with the .schem extension, nor with the .schematic extension."); DimDoors.log.warn("Schematic '" + id + "' was not found in the jar or config directory, neither with the .schem extension, nor with the .schematic extension.");
} }
NBTTagCompound schematicNBT; NBTTagCompound schematicNBT;
@ -35,10 +35,10 @@ public abstract class BaseSchematicGateway extends BaseGateway {
if (streamOpened) { if (streamOpened) {
try { try {
schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream); schematicNBT = CompressedStreamTools.readCompressed(schematicDataStream);
schematic = SchematicConverter.convertSchematic(schematicNBT, name, null); schematic = SchematicConverter.convertSchematic(schematicNBT, id, null, null);
schematicDataStream.close(); schematicDataStream.close();
} catch (IOException ex) { } catch (IOException ex) {
DimDoors.log.error("Schematic file for " + name + " could not be read as a valid schematic NBT file.", ex); DimDoors.log.error("Schematic file for " + id + " could not be read as a valid schematic NBT file.", ex);
} finally { } finally {
try { try {
schematicDataStream.close(); schematicDataStream.close();

Some files were not shown because too many files have changed in this diff Show more