added blueprint deployer, for #1673
This commit is contained in:
parent
dd0bc3a41f
commit
830ba84c87
5 changed files with 137 additions and 2 deletions
39
api/buildcraft/api/blueprints/BlueprintDeployer.java
Executable file
39
api/buildcraft/api/blueprints/BlueprintDeployer.java
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is provided as a utility class for third-party mods that would
|
||||||
|
* like to easily deploy structures that are written in blueprints. It does
|
||||||
|
* not offer control on material that needs to get in, or how the structure
|
||||||
|
* is deployed, but allows to create contents of a blueprint in one cycle.
|
||||||
|
* Note that these functionalities will only work if BuildCraft is installed.
|
||||||
|
*/
|
||||||
|
public abstract class BlueprintDeployer {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The deployed instantiated by BuildCraft. This is set by the BuildCraft
|
||||||
|
* builder mod. Mods that want to work with BuildCraft not installed should
|
||||||
|
* check for this value to be not null.
|
||||||
|
*/
|
||||||
|
public static BlueprintDeployer instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deploy the contents of the blueprints as if the builder was located at
|
||||||
|
* {x, y, z} facing the direction dir.
|
||||||
|
*/
|
||||||
|
public abstract void deployBlueprint(World world, int x, int y, int z,
|
||||||
|
ForgeDirection dir, File file);
|
||||||
|
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ import net.minecraftforge.client.event.TextureStitchEvent;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.common.config.Configuration;
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import net.minecraftforge.common.config.Property;
|
import net.minecraftforge.common.config.Property;
|
||||||
|
import buildcraft.api.blueprints.BlueprintDeployer;
|
||||||
import buildcraft.api.blueprints.SchematicBlock;
|
import buildcraft.api.blueprints.SchematicBlock;
|
||||||
import buildcraft.api.blueprints.SchematicEntity;
|
import buildcraft.api.blueprints.SchematicEntity;
|
||||||
import buildcraft.api.blueprints.SchematicFactory;
|
import buildcraft.api.blueprints.SchematicFactory;
|
||||||
|
@ -105,6 +106,7 @@ import buildcraft.builders.urbanism.UrbanistToolsIconProvider;
|
||||||
import buildcraft.core.DefaultProps;
|
import buildcraft.core.DefaultProps;
|
||||||
import buildcraft.core.InterModComms;
|
import buildcraft.core.InterModComms;
|
||||||
import buildcraft.core.Version;
|
import buildcraft.core.Version;
|
||||||
|
import buildcraft.core.blueprints.RealBlueprintDeployer;
|
||||||
import buildcraft.core.proxy.CoreProxy;
|
import buildcraft.core.proxy.CoreProxy;
|
||||||
import cpw.mods.fml.common.Mod;
|
import cpw.mods.fml.common.Mod;
|
||||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||||
|
@ -312,6 +314,8 @@ public class BuildCraftBuilders extends BuildCraftMod {
|
||||||
SchematicFactory.registerSchematicFactory(SchematicMask.class, new SchematicFactoryMask());
|
SchematicFactory.registerSchematicFactory(SchematicMask.class, new SchematicFactoryMask());
|
||||||
SchematicFactory.registerSchematicFactory(SchematicEntity.class, new SchematicFactoryEntity());
|
SchematicFactory.registerSchematicFactory(SchematicEntity.class, new SchematicFactoryEntity());
|
||||||
|
|
||||||
|
BlueprintDeployer.instance = new RealBlueprintDeployer();
|
||||||
|
|
||||||
if (BuildCraftCore.loadDefaultRecipes) {
|
if (BuildCraftCore.loadDefaultRecipes) {
|
||||||
loadRecipes();
|
loadRecipes();
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,8 +156,16 @@ public class BlueprintDatabase {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
File blueprintFile = getBlueprintFile(id);
|
BlueprintBase bpt = load (getBlueprintFile(id));
|
||||||
|
|
||||||
|
if (bpt != null) {
|
||||||
|
bpt.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bpt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BlueprintBase load (File blueprintFile) {
|
||||||
if (blueprintFile.exists()) {
|
if (blueprintFile.exists()) {
|
||||||
try {
|
try {
|
||||||
FileInputStream f = new FileInputStream(blueprintFile);
|
FileInputStream f = new FileInputStream(blueprintFile);
|
||||||
|
@ -169,7 +177,6 @@ public class BlueprintDatabase {
|
||||||
|
|
||||||
BlueprintBase blueprint = BlueprintBase.loadBluePrint(nbt);
|
BlueprintBase blueprint = BlueprintBase.loadBluePrint(nbt);
|
||||||
blueprint.setData(data);
|
blueprint.setData(data);
|
||||||
blueprint.id = id;
|
|
||||||
|
|
||||||
return blueprint;
|
return blueprint;
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
|
|
|
@ -179,6 +179,58 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
||||||
recomputeNeededItems();
|
recomputeNeededItems();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void deploy () {
|
||||||
|
for (BuildingSlotBlock b : buildList) {
|
||||||
|
if (b.mode == Mode.ClearIfInvalid) {
|
||||||
|
context.world.setBlockToAir(b.x, b.y, b.z);
|
||||||
|
} else {
|
||||||
|
b.stackConsumed = new LinkedList<ItemStack>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (ItemStack stk : b.getRequirements(context)) {
|
||||||
|
if (stk != null) {
|
||||||
|
b.stackConsumed.add(stk.copy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// Defensive code against errors in implementers
|
||||||
|
t.printStackTrace();
|
||||||
|
BCLog.logger.throwing("BptBuilderBlueprint", "checkRequirements", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
b.writeToWorld(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BuildingSlotEntity e : entityList) {
|
||||||
|
e.stackConsumed = new LinkedList<ItemStack>();
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (ItemStack stk : e.getRequirements(context)) {
|
||||||
|
if (stk != null) {
|
||||||
|
e.stackConsumed.add(stk.copy());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// Defensive code against errors in implementers
|
||||||
|
t.printStackTrace();
|
||||||
|
BCLog.logger.throwing("BptBuilderBlueprint", "checkRequirements", t);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.writeToWorld(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BuildingSlotBlock b : buildList) {
|
||||||
|
if (b.mode != Mode.ClearIfInvalid) {
|
||||||
|
b.postProcessing(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (BuildingSlotEntity e : entityList) {
|
||||||
|
e.postProcessing(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkDone() {
|
private void checkDone() {
|
||||||
recomputeNeededItems();
|
recomputeNeededItems();
|
||||||
|
|
||||||
|
|
33
common/buildcraft/core/blueprints/RealBlueprintDeployer.java
Executable file
33
common/buildcraft/core/blueprints/RealBlueprintDeployer.java
Executable file
|
@ -0,0 +1,33 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||||
|
* http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||||
|
* 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.core.blueprints;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
import buildcraft.api.blueprints.BlueprintDeployer;
|
||||||
|
import buildcraft.builders.blueprints.BlueprintDatabase;
|
||||||
|
import buildcraft.builders.blueprints.BlueprintId;
|
||||||
|
import buildcraft.builders.blueprints.BlueprintId.Kind;
|
||||||
|
|
||||||
|
public class RealBlueprintDeployer extends BlueprintDeployer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deployBlueprint(World world, int x, int y, int z,
|
||||||
|
ForgeDirection dir, File file) {
|
||||||
|
|
||||||
|
Blueprint bpt = (Blueprint) BlueprintDatabase.load(file);
|
||||||
|
bpt.id = new BlueprintId();
|
||||||
|
bpt.id.kind = Kind.Blueprint;
|
||||||
|
|
||||||
|
new BptBuilderBlueprint(bpt, world, x, y, z).deploy ();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue