Implemented builder state save for filler and quarry.

Fixed API, and moved out some non-essencial files.
Close #1618
This commit is contained in:
SpaceToad 2014-05-01 23:40:30 +02:00
parent f4ec1c6ca4
commit 5bd9aec80a
15 changed files with 169 additions and 91 deletions

View file

@ -34,10 +34,6 @@ package buildcraft.api.blueprints;
*/
public abstract class SchematicBlockBase extends Schematic {
public void writeCompleted(IBuilderContext context, int x, int y, int z, double completed) {
}
/**
* Return true if the block should not be placed to the world. Requirements
* will not be asked on such a block, and building will not be called.

View file

@ -57,20 +57,6 @@ public class SchematicMask extends SchematicBlockBase {
}
}
// TODO: To be removed with the "real" list of items
@Override
public void addRequirements(IBuilderContext context, LinkedList<ItemStack> requirements) {
requirements.add(new ItemStack(Blocks.brick_block));
}
@Override
public void writeCompleted(IBuilderContext context, int x, int y, int z, double completed) {
if (!isConcrete) {
context.world().destroyBlockInWorldPartially(0, x, y, z,
(int) (completed * 10.0F) - 1);
}
}
@Override
public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) {
nbt.setBoolean("isConcrete", isConcrete);

View file

@ -18,7 +18,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import buildcraft.core.BuildCraftConfiguration;
import buildcraft.api.core.JavaTools;
public class SchematicRegistry {
@ -138,14 +138,14 @@ public class SchematicRegistry {
return !modsForbidden.contains(modid) && !blocksForbidden.contains(name);
}
public static void readConfiguration (BuildCraftConfiguration conf) {
public static void readConfiguration (Configuration conf) {
Property excludedMods = conf.get(Configuration.CATEGORY_GENERAL, "builder.excludedMods", new String [0],
"mods that should be excluded from the builder.");
Property excludedBlocks = conf.get(Configuration.CATEGORY_GENERAL, "builder.excludedBlocks", new String [0],
"blocks that should be excluded from the builder.");
for (String id : excludedMods.getStringList()) {
id = BuildCraftConfiguration.stripSurroundingQuotes (id.trim());
id = JavaTools.stripSurroundingQuotes (id.trim());
if (id.length() > 0) {
modsForbidden.add(id);
@ -153,7 +153,7 @@ public class SchematicRegistry {
}
for (String id : excludedBlocks.getStringList()) {
id = BuildCraftConfiguration.stripSurroundingQuotes (id.trim());
id = JavaTools.stripSurroundingQuotes (id.trim());
if (id.length() > 0) {
blocksForbidden.add(id);

View file

@ -78,4 +78,12 @@ public class JavaTools {
return result;
}
public static String surroundWithQuotes(String stringToSurroundWithQuotes){
return String.format("\"%s\"", stringToSurroundWithQuotes);
}
public static String stripSurroundingQuotes(String stringToStripQuotes) {
return stringToStripQuotes.replaceAll("^\"|\"$", "");
}
}

View file

@ -27,9 +27,6 @@ import net.minecraftforge.common.config.Property;
import buildcraft.api.blueprints.SchematicBlock;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.blueprints.SchematicFactory;
import buildcraft.api.blueprints.SchematicFactoryBlock;
import buildcraft.api.blueprints.SchematicFactoryEntity;
import buildcraft.api.blueprints.SchematicFactoryMask;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.BCLog;
@ -73,6 +70,9 @@ import buildcraft.builders.schematics.SchematicCustomStack;
import buildcraft.builders.schematics.SchematicDirt;
import buildcraft.builders.schematics.SchematicDoor;
import buildcraft.builders.schematics.SchematicEnderChest;
import buildcraft.builders.schematics.SchematicFactoryBlock;
import buildcraft.builders.schematics.SchematicFactoryEntity;
import buildcraft.builders.schematics.SchematicFactoryMask;
import buildcraft.builders.schematics.SchematicFarmland;
import buildcraft.builders.schematics.SchematicFire;
import buildcraft.builders.schematics.SchematicFluid;

View file

@ -23,13 +23,13 @@ import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.RecipeSorter;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.JavaTools;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.GateExpansions;
import buildcraft.api.recipes.BuildcraftRecipes;
import buildcraft.api.transport.IExtractionHandler;
import buildcraft.api.transport.PipeManager;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.BuildCraftConfiguration;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.DefaultProps;
import buildcraft.core.InterModComms;
@ -295,16 +295,16 @@ public class BuildCraftTransport extends BuildCraftMod {
Block.blockRegistry.getNameForObject(Blocks.double_stone_slab),
Block.blockRegistry.getNameForObject(Blocks.double_wooden_slab),
Block.blockRegistry.getNameForObject(Blocks.sponge),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.architectBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.builderBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.fillerBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.libraryBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.autoWorkbenchBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.floodGateBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.miningWellBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.pumpBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.quarryBlock)),
BuildCraftConfiguration.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftTransport.filteredBufferBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.architectBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.builderBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.fillerBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftBuilders.libraryBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.autoWorkbenchBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.floodGateBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.miningWellBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.pumpBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftFactory.quarryBlock)),
JavaTools.surroundWithQuotes(Block.blockRegistry.getNameForObject(BuildCraftTransport.filteredBufferBlock)),
});
facadeBlacklistProp.comment = "Blocks listed here will not have facades created. The format is modid:blockname.\nFor mods with a | character, the value needs to be surrounded with quotes.";

View file

@ -58,7 +58,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
private LinkedList <ItemStack> requiredToBuild;
NBTTagCompound initNBT = null;
private NBTTagCompound initNBT = null;
private class PathIterator {
@ -215,7 +215,6 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
}
if (bluePrintBuilder != null) {
NBTTagCompound builderCpt = new NBTTagCompound();
bluePrintBuilder.loadBuildStateToNBT(
initNBT.getCompoundTag("builderState"), this);
}

View file

@ -52,6 +52,8 @@ public class TileFiller extends TileAbstractBuilder implements IMachine, IAction
private ActionMachineControl.Mode lastMode = ActionMachineControl.Mode.Unknown;
private SimpleInventory inv = new SimpleInventory(27, "Filler", 64);
private NBTTagCompound initNBT = null;
public TileFiller() {
inv.addListener(this);
box.kind = Kind.STRIPES;
@ -61,19 +63,35 @@ public class TileFiller extends TileAbstractBuilder implements IMachine, IAction
public void initialize() {
super.initialize();
if (!worldObj.isRemote) {
IAreaProvider a = Utils.getNearbyAreaProvider(worldObj, xCoord, yCoord, zCoord);
if (a != null) {
box.initialize(a);
if (a instanceof TileMarker) {
((TileMarker) a).removeFromWorld();
}
sendNetworkUpdate();
}
if (worldObj.isRemote) {
return;
}
IAreaProvider a = Utils.getNearbyAreaProvider(worldObj, xCoord, yCoord,
zCoord);
if (a != null) {
box.initialize(a);
if (a instanceof TileMarker) {
((TileMarker) a).removeFromWorld();
}
sendNetworkUpdate();
}
if (currentPattern != null && currentTemplate == null) {
currentTemplate = currentPattern
.getTemplateBuilder(box, getWorld());
context = currentTemplate.getContext();
}
if (initNBT != null && currentTemplate != null) {
currentTemplate.loadBuildStateToNBT(
initNBT.getCompoundTag("builderState"), this);
}
initNBT = null;
}
@Override
@ -92,7 +110,7 @@ public class TileFiller extends TileAbstractBuilder implements IMachine, IAction
return;
}
if (mjStored < POWER_ACTIVATION && !buildTracker.markTimeIfDelay(worldObj)) {
if (mjStored < POWER_ACTIVATION || !buildTracker.markTimeIfDelay(worldObj)) {
return;
}
@ -175,6 +193,9 @@ public class TileFiller extends TileAbstractBuilder implements IMachine, IAction
done = nbt.getBoolean("done");
lastMode = Mode.values()[nbt.getByte("lastMode")];
// The rest of load has to be done upon initialize.
initNBT = (NBTTagCompound) nbt.getCompoundTag("bpt").copy();
}
@Override
@ -193,6 +214,16 @@ public class TileFiller extends TileAbstractBuilder implements IMachine, IAction
nbt.setBoolean("done", done);
nbt.setByte("lastMode", (byte) lastMode.ordinal());
NBTTagCompound bptNBT = new NBTTagCompound();
if (currentTemplate != null) {
NBTTagCompound builderCpt = new NBTTagCompound();
currentTemplate.saveBuildStateToNBT(builderCpt, this);
bptNBT.setTag("builderState", builderCpt);
}
nbt.setTag("bpt", bptNBT);
}
@Override

View file

@ -6,8 +6,12 @@
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.blueprints;
package buildcraft.builders.schematics;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicBlock;
import buildcraft.api.blueprints.SchematicFactory;
import buildcraft.api.blueprints.SchematicRegistry;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;

View file

@ -6,8 +6,12 @@
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.blueprints;
package buildcraft.builders.schematics;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.blueprints.SchematicFactory;
import buildcraft.api.blueprints.SchematicRegistry;
import net.minecraft.nbt.NBTTagCompound;
public class SchematicFactoryEntity extends SchematicFactory <SchematicEntity> {

View file

@ -6,8 +6,11 @@
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.api.blueprints;
package buildcraft.builders.schematics;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicFactory;
import buildcraft.api.blueprints.SchematicMask;
import net.minecraft.nbt.NBTTagCompound;
public class SchematicFactoryMask extends SchematicFactory <SchematicMask> {

View file

@ -9,6 +9,7 @@
package buildcraft.core;
import java.io.File;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
@ -24,12 +25,4 @@ public class BuildCraftConfiguration extends Configuration {
versionProp.set(Version.VERSION);
super.save();
}
public static String surroundWithQuotes(String stringToSurroundWithQuotes){
return String.format("\"%s\"", stringToSurroundWithQuotes);
}
public static String stripSurroundingQuotes(String stringToStripQuotes) {
return stringToStripQuotes.replaceAll("^\"|\"$", "");
}
}

View file

@ -12,13 +12,14 @@ import java.util.LinkedList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicBlockBase;
import buildcraft.api.blueprints.SchematicFactory;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.Position;
public class BuildingSlotBlock extends BuildingSlot {
@ -93,8 +94,9 @@ public class BuildingSlotBlock extends BuildingSlot {
@Override
public void writeCompleted (IBuilderContext context, double complete) {
if (BuildCraftAPI.isSoftBlock(context.world(), x, y, z)) {
getSchematic().writeCompleted(context, x, y, z, complete);
if (mode == Mode.ClearIfInvalid) {
context.world().destroyBlockInWorldPartially(0, x, y, z,
(int) (complete * 10.0F) - 1);
}
}
@ -110,10 +112,22 @@ public class BuildingSlotBlock extends BuildingSlot {
nbt.setInteger("y", y);
nbt.setInteger("z", z);
NBTTagCompound schematicNBT = new NBTTagCompound();
SchematicFactory.getFactory(schematic.getClass())
.saveSchematicToWorldNBT(schematicNBT, schematic, registry);
nbt.setTag("schematic", schematicNBT);
if (schematic != null) {
NBTTagCompound schematicNBT = new NBTTagCompound();
SchematicFactory.getFactory(schematic.getClass())
.saveSchematicToWorldNBT(schematicNBT, schematic, registry);
nbt.setTag("schematic", schematicNBT);
}
NBTTagList nbtStacks = new NBTTagList ();
for (ItemStack stack : stackConsumed) {
NBTTagCompound nbtStack = new NBTTagCompound();
stack.writeToNBT(nbtStack);
nbtStacks.appendTag(nbtStack);
}
nbt.setTag("stackConsumed", nbtStacks);
}
@Override
@ -123,8 +137,20 @@ public class BuildingSlotBlock extends BuildingSlot {
y = nbt.getInteger("y");
z = nbt.getInteger("z");
schematic = (SchematicBlockBase) SchematicFactory
if (nbt.hasKey("schematic")) {
schematic = (SchematicBlockBase) SchematicFactory
.createSchematicFromWorldNBT(nbt.getCompoundTag("schematic"), registry);
}
stackConsumed = new LinkedList<ItemStack>();
NBTTagList nbtStacks = nbt.getTagList("stackConsumed", Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < nbtStacks.tagCount(); ++i) {
stackConsumed.add(ItemStack.loadItemStackFromNBT(nbtStacks
.getCompoundTagAt(i)));
}
}
@Override

View file

@ -87,7 +87,9 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
private Ticket chunkTicket;
public EntityPlayer placedBy;
boolean frameProducer = true;
private boolean frameProducer = true;
private NBTTagCompound initNBT = null;
public TileQuarry () {
box.kind = Kind.STRIPES;
@ -167,7 +169,9 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
if (stage == Stage.BUILDING) {
if (builder != null && !builder.isDone(this)) {
builder.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord);
if (buildTracker.markTimeIfDelay(worldObj)) {
builder.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord);
}
} else {
stage = Stage.IDLE;
}
@ -360,6 +364,9 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
headPosX = nbttagcompound.getDouble("headPosX");
headPosY = nbttagcompound.getDouble("headPosY");
headPosZ = nbttagcompound.getDouble("headPosZ");
// The rest of load has to be done upon initialize.
initNBT = (NBTTagCompound) nbttagcompound.getCompoundTag("bpt").copy();
}
@Override
@ -376,6 +383,16 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
NBTTagCompound boxTag = new NBTTagCompound();
box.writeToNBT(boxTag);
nbttagcompound.setTag("box", boxTag);
NBTTagCompound bptNBT = new NBTTagCompound();
if (builder != null) {
NBTTagCompound builderCpt = new NBTTagCompound();
builder.saveBuildStateToNBT(builderCpt, this);
bptNBT.setTag("builderState", builderCpt);
}
nbttagcompound.setTag("bpt", bptNBT);
}
@SuppressWarnings("rawtypes")
@ -627,6 +644,13 @@ public class TileQuarry extends TileAbstractBuilder implements IMachine {
createUtilsIfNeeded();
if (initNBT != null && builder != null) {
builder.loadBuildStateToNBT(
initNBT.getCompoundTag("builderState"), this);
}
initNBT = null;
sendNetworkUpdate();
}

View file

@ -8,19 +8,10 @@
*/
package buildcraft.transport;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.Position;
import buildcraft.api.recipes.BuildcraftRecipes;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.BlockSpring;
import buildcraft.core.BuildCraftConfiguration;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.proxy.CoreProxy;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
@ -34,10 +25,21 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.JavaTools;
import buildcraft.api.core.Position;
import buildcraft.api.recipes.BuildcraftRecipes;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.BlockSpring;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.proxy.CoreProxy;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import com.google.common.base.Strings;
import com.google.common.collect.Sets;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class ItemFacade extends ItemBuildCraft {
@ -121,14 +123,16 @@ public class ItemFacade extends ItemBuildCraft {
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World worldObj, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
if (worldObj.isRemote)
if (worldObj.isRemote) {
return false;
}
Position pos = new Position(x, y, z, ForgeDirection.getOrientation(side));
pos.moveForwards(1.0);
TileEntity tile = worldObj.getTileEntity((int) pos.x, (int) pos.y, (int) pos.z);
if (!(tile instanceof TileGenericPipe))
if (!(tile instanceof TileGenericPipe)) {
return false;
}
TileGenericPipe pipeTile = (TileGenericPipe) tile;
if (pipeTile.addFacade(ForgeDirection.getOrientation(side).getOpposite(), ItemFacade.getType(stack), ItemFacade.getWireType(stack), ItemFacade.getBlocks(stack), ItemFacade.getMetaValues(stack))) {
@ -194,7 +198,7 @@ public class ItemFacade extends ItemBuildCraft {
}
for (String blacklistedBlock : BuildCraftTransport.facadeBlacklist) {
if(blockName.equals(BuildCraftConfiguration.stripSurroundingQuotes(blacklistedBlock))) {
if(blockName.equals(JavaTools.stripSurroundingQuotes(blacklistedBlock))) {
return true;
}
}