From fe5e734b647101a8f5aa556ebb6c0dde511c0692 Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Mon, 5 May 2014 17:01:48 +0200 Subject: [PATCH] Added provision for blueprints with non existing blocks and entities. Close #1702 --- .../assets/buildcraft/lang/en_US.lang | 1 + common/buildcraft/builders/ItemBlueprint.java | 8 ++++ .../buildcraft/core/blueprints/Blueprint.java | 45 ++++++++++++------- .../core/blueprints/BlueprintBase.java | 1 + 4 files changed, 38 insertions(+), 17 deletions(-) diff --git a/buildcraft_resources/assets/buildcraft/lang/en_US.lang b/buildcraft_resources/assets/buildcraft/lang/en_US.lang index 3f709a97..410a9eab 100755 --- a/buildcraft_resources/assets/buildcraft/lang/en_US.lang +++ b/buildcraft_resources/assets/buildcraft/lang/en_US.lang @@ -138,6 +138,7 @@ item.blueprint.author=by item.blueprint.blank=Blank item.blueprint.creative_only=Creative Only item.blueprint.no_build=No Building +item.blueprint.incomplete=Incomplete item.PipeItemsWood.name=Wooden Transport Pipe item.PipeItemsCobblestone.name=Cobblestone Transport Pipe item.PipeItemsStone.name=Stone Transport Pipe diff --git a/common/buildcraft/builders/ItemBlueprint.java b/common/buildcraft/builders/ItemBlueprint.java index 4c06bed6..863ec4b0 100644 --- a/common/buildcraft/builders/ItemBlueprint.java +++ b/common/buildcraft/builders/ItemBlueprint.java @@ -57,6 +57,14 @@ public abstract class ItemBlueprint extends ItemBuildCraft { list.add(String.format(StringUtils.localize("item.blueprint.no_build"))); } } + + if (NBTUtils.getItemData(stack).hasKey("isComplete")) { + boolean isComplete = NBTUtils.getItemData(stack).getBoolean("isComplete"); + + if (!isComplete) { + list.add(String.format(StringUtils.localize("item.blueprint.incomplete"))); + } + } } public static BlueprintId getId (ItemStack stack) { diff --git a/common/buildcraft/core/blueprints/Blueprint.java b/common/buildcraft/core/blueprints/Blueprint.java index d845aea2..d2022094 100644 --- a/common/buildcraft/core/blueprints/Blueprint.java +++ b/common/buildcraft/core/blueprints/Blueprint.java @@ -196,22 +196,27 @@ public class Blueprint extends BlueprintBase { index++; if (cpt.hasKey("blockId")) { - int blockId = cpt.getInteger("blockId"); + Block block = mapping.getBlockForId(cpt.getInteger("blockId")); - contents[x][y][z] = SchematicRegistry.newSchematicBlock(mapping.getBlockForId(blockId)); - contents[x][y][z].readFromNBT(cpt, mapping); + if (block != null) { + contents[x][y][z] = SchematicRegistry.newSchematicBlock(block); + contents[x][y][z].readFromNBT(cpt, mapping); - switch (contents[x][y][z].getBuildingPermission()) { - case ALL: - break; - case CREATIVE_ONLY: - if (buildingPermission == BuildingPermission.ALL) { - buildingPermission = BuildingPermission.CREATIVE_ONLY; + switch (contents[x][y][z].getBuildingPermission()) { + case ALL: + break; + case CREATIVE_ONLY: + if (buildingPermission == BuildingPermission.ALL) { + buildingPermission = BuildingPermission.CREATIVE_ONLY; + } + break; + case NONE: + buildingPermission = BuildingPermission.NONE; + break; } - break; - case NONE: - buildingPermission = BuildingPermission.NONE; - break; + } else { + contents[x][y][z] = null; + isComplete = false; } } else { contents[x][y][z] = null; @@ -227,10 +232,15 @@ public class Blueprint extends BlueprintBase { NBTTagCompound cpt = entitiesNBT.getCompoundTagAt(i); if (cpt.hasKey("entityId")) { - int entityId = cpt.getInteger("entityId"); - SchematicEntity s = SchematicRegistry.newSchematicEntity(mapping.getEntityForId(entityId)); - s.readFromNBT(cpt, mapping); - entities.add(s); + Class entity = mapping.getEntityForId(cpt.getInteger("entityId")); + + if (entity != null) { + SchematicEntity s = SchematicRegistry.newSchematicEntity(entity); + s.readFromNBT(cpt, mapping); + entities.add(s); + } else { + isComplete = false; + } } } } @@ -243,6 +253,7 @@ public class Blueprint extends BlueprintBase { nbt.setString("author", author); nbt.setString("name", id.name); nbt.setByte ("permission", (byte) buildingPermission.ordinal()); + nbt.setBoolean("isComplete", isComplete); return stack; } diff --git a/common/buildcraft/core/blueprints/BlueprintBase.java b/common/buildcraft/core/blueprints/BlueprintBase.java index 7b22c913..bff744d8 100644 --- a/common/buildcraft/core/blueprints/BlueprintBase.java +++ b/common/buildcraft/core/blueprints/BlueprintBase.java @@ -36,6 +36,7 @@ public abstract class BlueprintBase { public boolean rotate = true; public boolean excavate = true; public BuildingPermission buildingPermission = BuildingPermission.ALL; + public boolean isComplete = true; protected MappingRegistry mapping = new MappingRegistry();