filler parameters, early revision

This commit is contained in:
asiekierka 2015-01-24 23:23:47 +01:00
parent 281d7409f9
commit 9c6a38eb6e
24 changed files with 465 additions and 181 deletions

View file

@ -12,13 +12,7 @@ import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.api.statements.IStatement;
public interface IFillerPattern {
String getUniqueTag();
@SideOnly(Side.CLIENT)
IIcon getIcon();
String getDisplayName();
public interface IFillerPattern extends IStatement {
}

View file

@ -6,7 +6,7 @@
* Please check the contents of the license, which should be located
* as "LICENSE.API" in the BuildCraft source code distribution.
*/
@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|filler")
@API(apiVersion = "3.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|filler")
package buildcraft.api.filler;
import cpw.mods.fml.common.API;

View file

@ -17,7 +17,7 @@ import cpw.mods.fml.relauncher.SideOnly;
public interface IStatement {
/**
* Every trigger needs a unique tag, it should be in the format of
* Every statement needs a unique tag, it should be in the format of
* "<modid>:<name>.
*
* @return the unique id
@ -31,27 +31,27 @@ public interface IStatement {
void registerIcons(IIconRegister iconRegister);
/**
* Return the maximum number of parameter this trigger can have, 0 if none.
* Return the maximum number of parameter this statement can have, 0 if none.
*/
int maxParameters();
/**
* Return the minimum number of parameter this trigger can have, 0 if none.
* Return the minimum number of parameter this statement can have, 0 if none.
*/
int minParameters();
/**
* Return the trigger description in the UI
* Return the statement description in the UI
*/
String getDescription();
/**
* Create parameters for the trigger.
* Create parameters for the statement.
*/
IStatementParameter createParameter(int index);
/**
* This returns the trigger after a left rotation. Used in particular in
* This returns the statement after a left rotation. Used in particular in
* blueprints orientation.
*/
IStatement rotateLeft();

View file

@ -135,6 +135,7 @@ import buildcraft.core.builders.patterns.PatternFill;
import buildcraft.core.builders.patterns.PatternFlatten;
import buildcraft.core.builders.patterns.PatternFrame;
import buildcraft.core.builders.patterns.PatternHorizon;
import buildcraft.core.builders.patterns.PatternParameterYDir;
import buildcraft.core.builders.patterns.PatternPyramid;
import buildcraft.core.builders.patterns.PatternStairs;
import buildcraft.core.proxy.CoreProxy;
@ -526,6 +527,8 @@ public class BuildCraftBuilders extends BuildCraftMod {
}
StatementManager.registerActionProvider(new BuildersActionProvider());
StatementManager.registerParameterClass(PatternParameterYDir.class);
}
public static void loadRecipes() {
@ -576,7 +579,7 @@ public class BuildCraftBuilders extends BuildCraftMod {
public void loadTextures(TextureStitchEvent.Pre evt) {
if (evt.map.getTextureType() == 0) {
for (FillerPattern pattern : FillerPattern.patterns.values()) {
pattern.registerIcon(evt.map);
pattern.registerIcons(evt.map);
}
}
}

View file

@ -13,6 +13,7 @@ import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import cpw.mods.fml.relauncher.Side;
@ -20,6 +21,9 @@ import cpw.mods.fml.relauncher.Side;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.IAreaProvider;
import buildcraft.api.filler.FillerManager;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementManager;
import buildcraft.api.tiles.IControllable;
import buildcraft.api.tiles.IHasWork;
import buildcraft.core.Box;
@ -35,11 +39,12 @@ import buildcraft.core.network.ICommandReceiver;
import buildcraft.core.network.PacketCommand;
import buildcraft.core.utils.Utils;
public class TileFiller extends TileAbstractBuilder implements IHasWork, IControllable, ICommandReceiver {
public class TileFiller extends TileAbstractBuilder implements IHasWork, IControllable, ICommandReceiver, IStatementContainer {
private static int POWER_ACTIVATION = 500;
public FillerPattern currentPattern = PatternFill.INSTANCE;
public IStatementParameter[] patternParameters;
private BptBuilderTemplate currentTemplate;
private BptContext context;
@ -76,9 +81,9 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
sendNetworkUpdate();
}
if (currentPattern != null && currentTemplate == null) {
if (currentPattern != null && currentTemplate == null && box.isInitialized()) {
currentTemplate = currentPattern
.getTemplateBuilder(box, getWorldObj());
.getTemplateBuilder(box, getWorldObj(), patternParameters);
context = currentTemplate.getContext();
}
@ -121,7 +126,7 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
}
if (currentPattern != null && currentTemplate == null) {
currentTemplate = currentPattern.getTemplateBuilder(box, getWorldObj());
currentTemplate = currentPattern.getTemplateBuilder(box, getWorldObj(), patternParameters);
context = currentTemplate.getContext();
}
@ -183,6 +188,12 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
currentPattern = PatternFill.INSTANCE;
}
if (nbt.hasKey("pp")) {
readParametersFromNBT(nbt.getCompoundTag("pp"));
} else {
initPatternParameters();
}
if (nbt.hasKey("box")) {
box.initialize(nbt.getCompoundTag("box"));
}
@ -218,6 +229,10 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
}
nbt.setTag("bpt", bptNBT);
NBTTagCompound ppNBT = new NBTTagCompound();
writeParametersToNBT(ppNBT);
nbt.setTag("pp", ppNBT);
}
@Override
@ -241,27 +256,66 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
destroy();
}
private void initPatternParameters() {
patternParameters = new IStatementParameter[currentPattern.maxParameters()];
for (int i = 0; i < currentPattern.minParameters(); i++) {
patternParameters[i] = currentPattern.createParameter(i);
}
}
public void setPattern(FillerPattern pattern) {
if (pattern != null && currentPattern != pattern) {
currentPattern = pattern;
currentTemplate = null;
done = false;
initPatternParameters();
sendNetworkUpdate();
}
}
private void writeParametersToNBT(NBTTagCompound nbt) {
nbt.setByte("length", (byte) (patternParameters != null ? patternParameters.length : 0));
if (patternParameters != null) {
for (int i = 0; i < patternParameters.length; i++) {
if (patternParameters[i] != null) {
NBTTagCompound patternData = new NBTTagCompound();
patternData.setString("kind", patternParameters[i].getUniqueTag());
patternParameters[i].writeToNBT(patternData);
nbt.setTag("p" + i, patternData);
}
}
}
}
private void readParametersFromNBT(NBTTagCompound nbt) {
patternParameters = new IStatementParameter[nbt.getByte("length")];
for (int i = 0; i < patternParameters.length; i++) {
if (nbt.hasKey("p" + i)) {
NBTTagCompound patternData = nbt.getCompoundTag("p" + i);
patternParameters[i] = StatementManager.createParameter(patternData.getString("kind"));
patternParameters[i].readFromNBT(patternData);
}
}
}
@Override
public void writeData(ByteBuf data) {
box.writeData(data);
data.writeBoolean(done);
Utils.writeUTF(data, currentPattern.getUniqueTag());
NBTTagCompound parameterData = new NBTTagCompound();
writeParametersToNBT(parameterData);
Utils.writeNBT(data, parameterData);
}
@Override
public void readData(ByteBuf data) {
box.readData(data);
done = data.readBoolean();
setPattern((FillerPattern) FillerManager.registry.getPattern(Utils.readUTF(data)));
FillerPattern pattern = (FillerPattern) FillerManager.registry.getPattern(Utils.readUTF(data));
NBTTagCompound parameterData = Utils.readNBT(data);
readParametersFromNBT(parameterData);
setPattern(pattern);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@ -298,6 +352,9 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
if (side.isServer() && "setPattern".equals(command)) {
String name = Utils.readUTF(stream);
setPattern((FillerPattern) FillerManager.registry.getPattern(name));
} else if (side.isServer() && "setParameters".equals(command)) {
NBTTagCompound patternData = Utils.readNBT(stream);
readParametersFromNBT(patternData);
}
}
@ -328,4 +385,18 @@ public class TileFiller extends TileAbstractBuilder implements IHasWork, IContro
mode == IControllable.Mode.Loop;
}
@Override
public TileEntity getTile() {
return this;
}
public void rpcSetParameter(int i, IStatementParameter patternParameter) {
BuildCraftCore.instance.sendToServer(new PacketCommand(this, "setParameters", new CommandWriter() {
public void write(ByteBuf data) {
NBTTagCompound parameterData = new NBTTagCompound();
writeParametersToNBT(parameterData);
Utils.writeNBT(data, parameterData);
}
}));
}
}

View file

@ -29,7 +29,7 @@ public class ContainerFiller extends BuildCraftContainer {
private class PatternWidget extends Widget {
public PatternWidget() {
super(80, 30, 0, 0, 16, 16);
super(38, 30, 0, 0, 16, 16);
}
@SideOnly(Side.CLIENT)

View file

@ -9,29 +9,69 @@
package buildcraft.builders.gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.inventory.IInventory;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import buildcraft.api.filler.FillerManager;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementMouseClick;
import buildcraft.builders.TileFiller;
import buildcraft.core.DefaultProps;
import buildcraft.core.builders.patterns.FillerPattern;
import buildcraft.core.gui.AdvancedSlot;
import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.gui.GuiBuildCraft;
import buildcraft.core.gui.GuiTools;
import buildcraft.core.gui.StatementParameterSlot;
import buildcraft.core.gui.StatementSlot;
import buildcraft.core.gui.buttons.GuiBetterButton;
import buildcraft.core.gui.buttons.StandardButtonTextureSets;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Pipe;
public class GuiFiller extends GuiBuildCraft {
public class GuiFiller extends GuiAdvancedInterface {
class FillerParameterSlot extends StatementParameterSlot {
public FillerParameterSlot(int x, int y, int slot) {
super(instance, x, y, slot, fakeStatementSlot);
}
@Override
public IStatementParameter getParameter() {
System.out.println("getParameter " + slot + " " + instance.filler.patternParameters.length);
if (slot >= instance.filler.patternParameters.length) {
return null;
} else {
return instance.filler.patternParameters[slot];
}
}
@Override
public void setParameter(IStatementParameter param, boolean notifyServer) {
// TODO
}
}
private static final ResourceLocation TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/filler.png");
IInventory playerInventory;
TileFiller filler;
private final IInventory playerInventory;
private final TileFiller filler;
private final GuiFiller instance;
private final StatementSlot fakeStatementSlot;
public GuiFiller(IInventory playerInventory, TileFiller filler) {
super(new ContainerFiller(playerInventory, filler), filler, TEXTURE);
this.playerInventory = playerInventory;
this.filler = filler;
this.instance = this;
this.fakeStatementSlot = new StatementSlot(instance, -1, -1, 0) {
@Override
public IStatement getStatement() {
return instance.filler.currentPattern;
}
};
xSize = 175;
ySize = 240;
}
@ -41,10 +81,15 @@ public class GuiFiller extends GuiBuildCraft {
super.initGui();
buttonList.clear();
buttonList.add(new GuiBetterButton(0, guiLeft + 80 - 18, guiTop + 30, 10,
buttonList.add(new GuiBetterButton(0, guiLeft + 38 - 18, guiTop + 30, 10,
StandardButtonTextureSets.LEFT_BUTTON, ""));
buttonList.add(new GuiBetterButton(1, guiLeft + 80 + 16 + 8, guiTop + 30, 10,
buttonList.add(new GuiBetterButton(1, guiLeft + 38 + 16 + 8, guiTop + 30, 10,
StandardButtonTextureSets.RIGHT_BUTTON, ""));
slots.clear();
for (int i = 0; i < 4; i++) {
slots.add(new FillerParameterSlot(77 + (i * 18), 30, i));
}
}
@Override
@ -61,11 +106,37 @@ public class GuiFiller extends GuiBuildCraft {
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
protected void mouseClicked(int x, int y, int k) {
super.mouseClicked(x, y, k);
AdvancedSlot slot = getSlotAtLocation(x, y);
if (slot != null) {
int i = ((FillerParameterSlot) slot).slot;
if (i < filler.patternParameters.length) {
if (filler.patternParameters[i] != null) {
filler.patternParameters[i].onClick(filler, filler.currentPattern, mc.thePlayer.inventory.getItemStack(),
new StatementMouseClick(k, isShiftKeyDown()));
} else {
filler.patternParameters[i] = filler.currentPattern.createParameter(i);
}
filler.rpcSetParameter(i, filler.patternParameters[i]);
}
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int mx, int my) {
super.drawGuiContainerBackgroundLayer(f, mx, my);
drawBackgroundSlots();
}
@Override
protected void drawGuiContainerForegroundLayer(int mx, int my) {
String title = StringUtils.localize("tile.fillerBlock.name");
fontRendererObj.drawString(title, getCenteredOffset(title), 6, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.filling.resources"), 8, 74, 0x404040);
fontRendererObj.drawString(StringUtils.localize("gui.inventory"), 8, 142, 0x404040);
GuiTools.drawCenteredString(fontRendererObj, filler.currentPattern.getDisplayName(), 56);
GuiTools.drawCenteredString(fontRendererObj, filler.currentPattern.getDescription(), 56);
}
}

View file

@ -31,7 +31,7 @@ public class ActionFiller extends BCStatement implements IActionExternal {
@Override
public String getDescription() {
return "Pattern: " + pattern.getDisplayName();
return "Pattern: " + pattern.getDescription();
}
@Override

View file

@ -65,7 +65,7 @@ class UrbanistToolFiller extends UrbanistToolArea {
@Override
public String getDescription() {
return getPattern().getDisplayName();
return getPattern().getDescription();
}
@Override

View file

@ -18,6 +18,8 @@ import net.minecraft.world.World;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.Blueprint;
import buildcraft.core.blueprints.BlueprintBase;
@ -38,16 +40,27 @@ public abstract class FillerPattern implements IFillerPattern {
}
@Override
public String getDisplayName() {
public String getDescription() {
return StringUtils.localize("fillerpattern." + tag);
}
@Override
public IStatementParameter createParameter(int index) {
return null;
}
@Override
public IStatement rotateLeft() {
return this;
}
@Override
public String getUniqueTag() {
return "buildcraft:" + tag;
}
public void registerIcon(IIconRegister iconRegister) {
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:fillerPatterns/" + tag);
}
@ -56,6 +69,16 @@ public abstract class FillerPattern implements IFillerPattern {
return icon;
}
@Override
public int maxParameters() {
return 0;
}
@Override
public int minParameters() {
return 0;
}
@Override
public String toString() {
return "Pattern: " + getUniqueTag();
@ -112,13 +135,13 @@ public abstract class FillerPattern implements IFillerPattern {
}
}
public abstract Template getTemplate (Box box, World world);
public abstract Template getTemplate (Box box, World world, IStatementParameter[] parameters);
public Blueprint getBlueprint (Box box, World world, Block block, int meta) {
public Blueprint getBlueprint (Box box, World world, IStatementParameter[] parameters, Block block, int meta) {
Blueprint result = new Blueprint (box.sizeX(), box.sizeY(), box.sizeZ());
try {
Template tmpl = getTemplate(box, world);
Template tmpl = getTemplate(box, world, parameters);
for (int x = 0; x < box.sizeX(); ++x) {
for (int y = 0; y < box.sizeY(); ++y) {
@ -139,8 +162,8 @@ public abstract class FillerPattern implements IFillerPattern {
return result;
}
public BptBuilderTemplate getTemplateBuilder (Box box, World world) {
return new BptBuilderTemplate(getTemplate(box, world), world, box.xMin, box.yMin, box.zMin);
public BptBuilderTemplate getTemplateBuilder (Box box, World world, IStatementParameter[] parameters) {
return new BptBuilderTemplate(getTemplate(box, world, parameters), world, box.xMin, box.yMin, box.zMin);
}
private static boolean isValid (int x, int y, int z, BlueprintBase bpt) {

View file

@ -10,6 +10,7 @@ package buildcraft.core.builders.patterns;
import net.minecraft.world.World;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.Template;
@ -21,7 +22,7 @@ public class PatternBox extends FillerPattern {
}
@Override
public Template getTemplate(Box box, World world) {
public Template getTemplate(Box box, World world, IStatementParameter[] parameters) {
Template result = new Template (box.sizeX(), box.sizeY(), box.sizeZ());
int xMin = 0;

View file

@ -10,6 +10,7 @@ package buildcraft.core.builders.patterns;
import net.minecraft.world.World;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.Template;
@ -20,7 +21,7 @@ public class PatternClear extends FillerPattern {
}
@Override
public Template getTemplate (Box box, World world) {
public Template getTemplate (Box box, World world, IStatementParameter[] parameters) {
int xMin = (int) box.pMin().x;
int yMin = (int) box.pMin().y;
int zMin = (int) box.pMin().z;

View file

@ -10,6 +10,7 @@ package buildcraft.core.builders.patterns;
import net.minecraft.world.World;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.Template;
@ -21,7 +22,7 @@ public class PatternCylinder extends FillerPattern {
@Override
public Template getTemplate(Box box, World world) {
public Template getTemplate(Box box, World world, IStatementParameter[] parameters) {
Template result = new Template (box.sizeX(), box.sizeY(), box.sizeZ());
int xMin = 0;

View file

@ -10,6 +10,7 @@ package buildcraft.core.builders.patterns;
import net.minecraft.world.World;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.Template;
@ -22,7 +23,7 @@ public final class PatternFill extends FillerPattern {
}
@Override
public Template getTemplate (Box box, World world) {
public Template getTemplate (Box box, World world, IStatementParameter[] parameters) {
Template bpt = new Template(box.sizeX(), box.sizeY(), box.sizeZ());
fill (0, 0, 0, box.sizeX() - 1, box.sizeY() - 1, box.sizeZ() - 1, bpt);

View file

@ -11,6 +11,7 @@ package buildcraft.core.builders.patterns;
import net.minecraft.world.World;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.BptBuilderTemplate;
import buildcraft.core.blueprints.Template;
@ -22,7 +23,7 @@ public class PatternFlatten extends FillerPattern {
}
@Override
public Template getTemplate (Box box, World world) {
public Template getTemplate (Box box, World world, IStatementParameter[] parameters) {
int xMin = (int) box.pMin().x;
int yMin = box.pMin().y > 0 ? (int) box.pMin().y - 1 : 0;
int zMin = (int) box.pMin().z;
@ -45,9 +46,9 @@ public class PatternFlatten extends FillerPattern {
}
@Override
public BptBuilderTemplate getTemplateBuilder (Box box, World world) {
public BptBuilderTemplate getTemplateBuilder (Box box, World world, IStatementParameter[] parameters) {
int yMin = box.pMin().y > 0 ? (int) box.pMin().y - 1 : 0;
return new BptBuilderTemplate(getTemplate(box, world), world, box.xMin, yMin, box.zMin);
return new BptBuilderTemplate(getTemplate(box, world, parameters), world, box.xMin, yMin, box.zMin);
}
}

View file

@ -11,6 +11,7 @@ package buildcraft.core.builders.patterns;
import net.minecraft.world.World;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.Template;
@ -22,7 +23,7 @@ public class PatternFrame extends FillerPattern {
}
@Override
public Template getTemplate(Box box, World world) {
public Template getTemplate(Box box, World world, IStatementParameter[] parameters) {
Template template = new Template (box.sizeX(), box.sizeY(), box.sizeZ());
int xMin = 0;

View file

@ -11,6 +11,7 @@ package buildcraft.core.builders.patterns;
import net.minecraft.world.World;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.BptBuilderTemplate;
import buildcraft.core.blueprints.Template;
@ -22,7 +23,7 @@ public class PatternHorizon extends FillerPattern {
}
@Override
public Template getTemplate (Box box, World world) {
public Template getTemplate (Box box, World world, IStatementParameter[] parameters) {
int xMin = (int) box.pMin().x;
int yMin = box.pMin().y > 0 ? (int) box.pMin().y - 1 : 0;
int zMin = (int) box.pMin().z;
@ -45,9 +46,9 @@ public class PatternHorizon extends FillerPattern {
}
@Override
public BptBuilderTemplate getTemplateBuilder (Box box, World world) {
public BptBuilderTemplate getTemplateBuilder (Box box, World world, IStatementParameter[] parameters) {
int yMin = box.pMin().y > 0 ? (int) box.pMin().y - 1 : 0;
return new BptBuilderTemplate(getTemplate(box, world), world, box.xMin, yMin, box.zMin);
return new BptBuilderTemplate(getTemplate(box, world, parameters), world, box.xMin, yMin, box.zMin);
}
}

View file

@ -0,0 +1,72 @@
package buildcraft.core.builders.patterns;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementContainer;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementMouseClick;
import buildcraft.core.utils.StringUtils;
public class PatternParameterYDir implements IStatementParameter {
private static IIcon iconUp, iconDown;
public boolean up = false;
public PatternParameterYDir() {
super();
}
public PatternParameterYDir(boolean up) {
this();
this.up = up;
}
@Override
public String getUniqueTag() {
return "buildcraft:fillerParameterYDir";
}
@Override
public IIcon getIcon() {
return up ? iconUp : iconDown;
}
@Override
public ItemStack getItemStack() {
return null;
}
@Override
public void registerIcons(IIconRegister iconRegister) {
iconUp = iconRegister.registerIcon("buildcraft:fillerParameters/arrow_up");
iconDown = iconRegister.registerIcon("buildcraft:fillerParameters/arrow_down");
}
@Override
public String getDescription() {
return StringUtils.localize("direction." + (up ? "up" : "down"));
}
@Override
public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse) {
up = !up;
}
@Override
public void readFromNBT(NBTTagCompound compound) {
up = compound.getBoolean("up");
}
@Override
public void writeToNBT(NBTTagCompound compound) {
compound.setBoolean("up", up);
}
@Override
public IStatementParameter rotateLeft() {
return null;
}
}

View file

@ -11,20 +11,32 @@ package buildcraft.core.builders.patterns;
import net.minecraft.world.World;
import buildcraft.api.blueprints.SchematicMask;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.Template;
public class PatternPyramid extends FillerPattern {
// TODO: These parameters need to be settable from the filler
private boolean param1 = true;
public PatternPyramid() {
super("pyramid");
}
@Override
public Template getTemplate (Box box, World world) {
public int maxParameters() {
return 1;
}
@Override
public int minParameters() {
return 1;
}
@Override
public IStatementParameter createParameter(int index) {
return new PatternParameterYDir(true);
}
@Override
public Template getTemplate (Box box, World world, IStatementParameter[] parameters) {
int xMin = (int) box.pMin().x;
int yMin = (int) box.pMin().y;
int zMin = (int) box.pMin().z;
@ -40,13 +52,12 @@ public class PatternPyramid extends FillerPattern {
int step = 0;
int height;
int stepY;
int stepY = 1;
if (param1) {
stepY = 1;
} else {
if (parameters[0] != null && !(((PatternParameterYDir) parameters[0]).up)) {
stepY = -1;
} else {
stepY = 1;
}
if (stepY == 1) {

View file

@ -10,13 +10,13 @@ package buildcraft.core.builders.patterns;
import net.minecraft.world.World;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.core.Box;
import buildcraft.core.blueprints.Template;
public class PatternStairs extends FillerPattern {
// TODO: These parameters need to be settable from the filler
private boolean param1 = true;
private int param2 = 0;
private int param3 = 0;
private int param4 = 0;
@ -26,7 +26,22 @@ public class PatternStairs extends FillerPattern {
}
@Override
public Template getTemplate(Box box, World world) {
public int maxParameters() {
return 1;
}
@Override
public int minParameters() {
return 1;
}
@Override
public IStatementParameter createParameter(int index) {
return new PatternParameterYDir(true);
}
@Override
public Template getTemplate(Box box, World world, IStatementParameter[] parameters) {
int xMin = 0;
int yMin = 0;
int zMin = 0;
@ -45,7 +60,7 @@ public class PatternStairs extends FillerPattern {
int dimX = 0;
int dimZ = 0;
if (param1) {
if (parameters[0] != null && !(((PatternParameterYDir) parameters[0]).up)) {
height = yMin;
heightStep = 1;
} else {

View file

@ -0,0 +1,73 @@
package buildcraft.core.gui;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.transport.Pipe;
import buildcraft.transport.gui.GuiGateInterface;
/**
* Created by asie on 1/24/15.
*/
public abstract class StatementParameterSlot extends AdvancedSlot {
public int slot;
public StatementSlot statementSlot;
public StatementParameterSlot(GuiAdvancedInterface gui, int x, int y, int slot, StatementSlot iStatementSlot) {
super(gui, x, y);
this.slot = slot;
this.statementSlot = iStatementSlot;
statementSlot.parameters.add(this);
}
@Override
public boolean isDefined() {
return getParameter() != null;
}
@Override
public String getDescription() {
IStatementParameter parameter = getParameter();
if (parameter != null) {
return parameter.getDescription() != null ? parameter.getDescription() : "";
} else {
return null;
}
}
@Override
public ItemStack getItemStack() {
IStatementParameter parameter = getParameter();
if (parameter != null) {
return parameter.getItemStack();
} else {
return null;
}
}
@Override
public IIcon getIcon() {
IStatementParameter parameter = getParameter();
if (parameter != null) {
return parameter.getIcon();
} else {
return null;
}
}
public abstract IStatementParameter getParameter();
public boolean isAllowed() {
return statementSlot.getStatement() != null && slot < statementSlot.getStatement().maxParameters();
}
public boolean isRequired() {
return statementSlot.getStatement() != null && slot < statementSlot.getStatement().minParameters();
}
public abstract void setParameter(IStatementParameter param, boolean notifyServer);
}

View file

@ -0,0 +1,53 @@
package buildcraft.core.gui;
import java.util.ArrayList;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.api.statements.IStatement;
import buildcraft.transport.Pipe;
import buildcraft.transport.gui.GuiGateInterface;
/**
* Created by asie on 1/24/15.
*/
public abstract class StatementSlot extends AdvancedSlot {
public int slot;
public ArrayList<StatementParameterSlot> parameters = new ArrayList<StatementParameterSlot>();
public StatementSlot(GuiAdvancedInterface gui, int x, int y, int slot) {
super(gui, x, y);
this.slot = slot;
}
@Override
public String getDescription() {
IStatement stmt = getStatement();
if (stmt != null) {
return stmt.getDescription();
} else {
return "";
}
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon() {
IStatement stmt = getStatement();
if (stmt != null) {
return stmt.getIcon();
} else {
return null;
}
}
@Override
public boolean isDefined() {
return getStatement() != null;
}
public abstract IStatement getStatement();
}

View file

@ -38,6 +38,7 @@ import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IAreaProvider;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.filler.FillerManager;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.tiles.IControllable;
import buildcraft.api.tiles.IHasWork;
import buildcraft.api.transport.IPipeConnection;
@ -604,7 +605,7 @@ public class TileQuarry extends TileAbstractBuilder implements IHasWork, ISidedI
private void initializeBlueprintBuilder() {
Blueprint bpt = ((FillerPattern) FillerManager.registry.getPattern("buildcraft:frame"))
.getBlueprint(box, worldObj, BuildCraftFactory.frameBlock, 0);
.getBlueprint(box, worldObj, new IStatementParameter[0], BuildCraftFactory.frameBlock, 0);
if (bpt != null) {
builder = new BptBuilderBlueprint(bpt, worldObj, box.xMin, yCoord, box.zMin);

View file

@ -8,25 +8,21 @@
*/
package buildcraft.transport.gui;
import java.util.ArrayList;
import java.util.Iterator;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.api.statements.IStatement;
import buildcraft.api.statements.IStatementParameter;
import buildcraft.api.statements.StatementMouseClick;
import buildcraft.core.gui.AdvancedSlot;
import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.gui.StatementParameterSlot;
import buildcraft.core.gui.StatementSlot;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.ActionActiveState;
import buildcraft.transport.Gate;
@ -34,56 +30,15 @@ import buildcraft.transport.Pipe;
import buildcraft.transport.gates.GateDefinition.GateMaterial;
public class GuiGateInterface extends GuiAdvancedInterface {
IInventory playerInventory;
private final ContainerGateInterface container;
private final GuiGateInterface instance;
private final Pipe<?> pipe;
private Gate gate;
private abstract class StatementSlot extends AdvancedSlot {
public int slot;
public ArrayList<StatementParameterSlot> parameters = new ArrayList<StatementParameterSlot>();
public StatementSlot(int x, int y, Pipe<?> pipe, int slot) {
super(GuiGateInterface.this, x, y);
this.slot = slot;
}
@Override
public String getDescription() {
IStatement stmt = getStatement();
if (stmt != null) {
return stmt.getDescription();
} else {
return "";
}
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon() {
IStatement stmt = getStatement();
if (stmt != null) {
return stmt.getIcon();
} else {
return null;
}
}
@Override
public boolean isDefined() {
return getStatement() != null;
}
public abstract IStatement getStatement();
}
private class TriggerSlot extends StatementSlot {
public TriggerSlot(int x, int y, Pipe<?> pipe, int slot) {
super(x, y, pipe, slot);
super(instance, x, y, slot);
}
@Override
@ -94,7 +49,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
private class ActionSlot extends StatementSlot {
public ActionSlot(int x, int y, Pipe<?> pipe, int slot) {
super(x, y, pipe, slot);
super(instance, x, y, slot);
}
@Override
@ -103,75 +58,9 @@ public class GuiGateInterface extends GuiAdvancedInterface {
}
}
private abstract class StatementParameterSlot extends AdvancedSlot {
public Pipe<?> pipe;
public int slot;
public StatementSlot statementSlot;
public StatementParameterSlot(int x, int y, Pipe<?> pipe, int slot, StatementSlot iStatementSlot) {
super(GuiGateInterface.this, x, y);
this.pipe = pipe;
this.slot = slot;
this.statementSlot = iStatementSlot;
statementSlot.parameters.add(this);
}
@Override
public boolean isDefined() {
return getParameter() != null;
}
@Override
public String getDescription() {
IStatementParameter parameter = getParameter();
if (parameter != null) {
return parameter.getDescription() != null ? parameter.getDescription() : "";
} else {
return null;
}
}
@Override
public ItemStack getItemStack() {
IStatementParameter parameter = getParameter();
if (parameter != null) {
return parameter.getItemStack();
} else {
return null;
}
}
@Override
public IIcon getIcon() {
IStatementParameter parameter = getParameter();
if (parameter != null) {
return parameter.getIcon();
} else {
return null;
}
}
public abstract IStatementParameter getParameter();
public boolean isAllowed() {
return statementSlot.getStatement() != null && slot < statementSlot.getStatement().maxParameters();
}
public boolean isRequired() {
return statementSlot.getStatement() != null && slot < statementSlot.getStatement().minParameters();
}
public abstract void setParameter(IStatementParameter param, boolean notifyServer);
}
class TriggerParameterSlot extends StatementParameterSlot {
public TriggerParameterSlot(int x, int y, Pipe<?> pipe, int slot, StatementSlot iStatementSlot) {
super(x, y, pipe, slot, iStatementSlot);
super(instance, x, y, slot, iStatementSlot);
}
@Override
@ -187,7 +76,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
class ActionParameterSlot extends StatementParameterSlot {
public ActionParameterSlot(int x, int y, Pipe<?> pipe, int slot, StatementSlot iStatementSlot) {
super(x, y, pipe, slot, iStatementSlot);
super(instance, x, y, slot, iStatementSlot);
}
@Override
@ -208,6 +97,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
container.gateCallback = this;
this.pipe = pipe;
this.playerInventory = playerInventory;
this.instance = this;
}
public void setGate(Gate gate) {