Skip to content

Commit

Permalink
Fix a few builder things
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexIIL committed Jan 3, 2016
1 parent 81b9693 commit 9bc255d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 3 additions & 1 deletion api/buildcraft/api/blueprints/SchematicTile.java
Expand Up @@ -49,7 +49,9 @@ public void placeInWorld(IBuilderContext context, BlockPos pos, List<ItemStack>
tileNBT.setInteger("x", pos.getX());
tileNBT.setInteger("y", pos.getY());
tileNBT.setInteger("z", pos.getZ());
context.world().setTileEntity(pos, TileEntity.createAndLoadEntity(tileNBT));
TileEntity tile = TileEntity.createAndLoadEntity(tileNBT);
tile.setWorldObj(context.world());
context.world().setTileEntity(pos, tile);
}
}

Expand Down
5 changes: 4 additions & 1 deletion common/buildcraft/core/builders/BuildingSlotBlock.java
Expand Up @@ -108,10 +108,14 @@ && getSchematic() instanceof SchematicBlock) {
boolean contains = false;
for (ItemStack ss : oldRequirements) {
if (getSchematic().isItemMatchingRequirement(s, ss)) {
BCLog.logger.info(" The item stack " + ss + " matched the stored requirement " + s);
contains = true;
break;
} else {
BCLog.logger.info(" The item stack " + ss + " DI NOT match the stored requirement " + s);
}
}
BCLog.logger.info("Old requriements size = " + oldRequirements.size());
if (!contains) {
BCLog.logger.warn(
"Blueprint has MISMATCHING REQUIREMENTS! Potential corrupted/hacked blueprint! Removed mismatched block.");
Expand All @@ -133,7 +137,6 @@ && getSchematic() instanceof SchematicBlock) {
// air.

TileEntity e = context.world().getTileEntity(pos);

if (e != null && e instanceof ITickable) {
((ITickable) e).update();
}
Expand Down
29 changes: 25 additions & 4 deletions common/buildcraft/transport/schematics/SchematicPipe.java
Expand Up @@ -15,6 +15,8 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;

import net.minecraftforge.common.util.Constants;

import buildcraft.api.blueprints.*;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementParameter;
Expand All @@ -33,7 +35,11 @@ public boolean isAlreadyBuilt(IBuilderContext context, BlockPos pos) {
Pipe<?> pipe = BlockGenericPipe.getPipe(context.world(), pos);

if (BlockGenericPipe.isValid(pipe)) {
return pipe.item == Item.getItemById(tileNBT.getInteger("pipeId"));
if (tileNBT.hasKey("pipeId", Constants.NBT.TAG_INT)) {
return pipe.item == Item.getItemById(tileNBT.getInteger("pipeId"));
} else {
return pipe.item == Item.getByNameOrId(tileNBT.getString("pipeId"));
}
} else {
return false;
}
Expand All @@ -47,7 +53,12 @@ public void rotateLeft(IBuilderContext context) {
props.rotateLeft();
props.writeToNBT(tileNBT);

Item pipeItem = Item.getItemById(tileNBT.getInteger("pipeId"));
Item pipeItem;
if (tileNBT.hasKey("pipeId", Constants.NBT.TAG_INT)) {
pipeItem = Item.getItemById(tileNBT.getInteger("pipeId"));
} else {
pipeItem = Item.getByNameOrId(tileNBT.getString("pipeId"));
}

if (BptPipeExtension.contains(pipeItem)) {
BptPipeExtension.get(pipeItem).rotateLeft(this, context);
Expand Down Expand Up @@ -146,6 +157,7 @@ public void placeInWorld(IBuilderContext context, BlockPos pos, List<ItemStack>
context.world().setBlockState(pos, state, 3);

TileEntity tile = context.world().getTileEntity(pos);
tile.setWorldObj(context.world());
tile.readFromNBT(tileNBT);
}

Expand Down Expand Up @@ -186,6 +198,11 @@ public void storeRequirements(IBuilderContext context, BlockPos pos) {
storedRequirements[storedRequirements.length - 1] = new ItemStack(pipe.item, 1, pipe.container.getItemMetadata());
}
}

@Override
public void getRequirementsForPlacement(IBuilderContext context, List<ItemStack> requirements) {

}

@Override
public void postProcessing(IBuilderContext context, BlockPos pos) {
Expand All @@ -205,9 +222,13 @@ public BuildingStage getBuildStage() {
public void idsToBlueprint(MappingRegistry registry) {
super.idsToBlueprint(registry);

if (tileNBT.hasKey("pipeId")) {
if (tileNBT.hasKey("pipeId", Constants.NBT.TAG_INT)) {
Item item = Item.getItemById(tileNBT.getInteger("pipeId"));

tileNBT.setInteger("pipeId", registry.getIdForItem(item));
} else if (tileNBT.hasKey("pipeId")) {
Item item = Item.getByNameOrId(tileNBT.getString("pipeId"));

tileNBT.setInteger("pipeId", registry.getIdForItem(item));
}
}
Expand All @@ -220,7 +241,7 @@ public void idsToWorld(MappingRegistry registry) {
try {
Item item = registry.getItemForId(tileNBT.getInteger("pipeId"));

tileNBT.setInteger("pipeId", Item.getIdFromItem(item));
tileNBT.setString("pipeId", Item.itemRegistry.getNameForObject(item).toString());
} catch (MappingNotFoundException e) {
tileNBT.removeTag("pipeId");
}
Expand Down

0 comments on commit 9bc255d

Please sign in to comment.