add center selection to pyramid code

This commit is contained in:
Adrian 2015-06-14 14:58:09 +02:00
parent cc687719fb
commit 81dea5a6fd
14 changed files with 144 additions and 119 deletions

View file

@ -147,6 +147,16 @@ direction.south=South
direction.up=Top
direction.down=Bottom
direction.center.0=North-West
direction.center.1=North
direction.center.2=North-East
direction.center.3=West
direction.center.4=Center
direction.center.5=East
direction.center.6=South-West
direction.center.7=South
direction.center.8=South-East
fillerpattern.clear=Clear
fillerpattern.fill=Fill
fillerpattern.flatten=Flatten

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 383 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

View file

@ -15,7 +15,6 @@ import java.nio.IntBuffer;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
@ -30,7 +29,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraft.util.IIcon;
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Loader;
@ -45,7 +43,6 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.IPlantable;
@ -105,6 +102,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.PatternParameterCenter;
import buildcraft.core.builders.patterns.PatternParameterXZDir;
import buildcraft.core.builders.patterns.PatternParameterYDir;
import buildcraft.core.builders.patterns.PatternPyramid;
@ -451,6 +449,7 @@ public class BuildCraftCore extends BuildCraftMod {
StatementManager.registerParameterClass(PatternParameterYDir.class);
StatementManager.registerParameterClass(PatternParameterXZDir.class);
StatementManager.registerParameterClass(PatternParameterCenter.class);
}
@Mod.EventHandler

View file

@ -0,0 +1,79 @@
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.lib.utils.StringUtils;
public class PatternParameterCenter implements IStatementParameter {
private static final int[] shiftLeft = {6, 3, 0, 7, 4, 1, 8, 5, 2};
private static IIcon[] icons;
private int direction;
public PatternParameterCenter() {
super();
}
public PatternParameterCenter(int direction) {
this();
this.direction = direction;
}
@Override
public String getUniqueTag() {
return "buildcraft:fillerParameterCenter";
}
@Override
public IIcon getIcon() {
return icons[direction % 9];
}
@Override
public ItemStack getItemStack() {
return null;
}
@Override
public void registerIcons(IIconRegister iconRegister) {
icons = new IIcon[9];
for (int i = 0; i < 9; i++) {
icons[i] = iconRegister.registerIcon("buildcraftcore:fillerParameters/center_" + i);
}
}
@Override
public String getDescription() {
return StringUtils.localize("direction.center." + direction);
}
@Override
public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse) {
direction = (direction + 1) % 9;
}
@Override
public void readFromNBT(NBTTagCompound compound) {
direction = compound.getByte("dir");
}
@Override
public void writeToNBT(NBTTagCompound compound) {
compound.setByte("dir", (byte) direction);
}
@Override
public IStatementParameter rotateLeft() {
return new PatternParameterCenter(shiftLeft[direction % 9]);
}
public int getDirection() {
return direction;
}
}

View file

@ -16,23 +16,35 @@ import buildcraft.core.Box;
import buildcraft.core.blueprints.Template;
public class PatternPyramid extends FillerPattern {
private static final int[] MODIFIERS = {
0x0101,
0x1101,
0x1001,
0x0111,
0x1111,
0x1011,
0x0110,
0x1110,
0x1010
};
public PatternPyramid() {
super("pyramid");
}
@Override
public int maxParameters() {
return 1;
return 2;
}
@Override
public int minParameters() {
return 1;
return 2;
}
@Override
public IStatementParameter createParameter(int index) {
return new PatternParameterYDir(true);
return index == 1 ? new PatternParameterCenter(4) : new PatternParameterYDir(true);
}
@Override
@ -47,34 +59,53 @@ public class PatternPyramid extends FillerPattern {
Template bpt = new Template(xMax - xMin + 1, yMax - yMin + 1, zMax - zMin + 1);
int xSize = xMax - xMin + 1;
int zSize = zMax - zMin + 1;
int step = 0;
int[] modifiers = new int[4];
int height;
int stepY;
if (parameters[0] != null && !(((PatternParameterYDir) parameters[0]).up)) {
if (parameters.length >= 1 && parameters[0] != null && !(((PatternParameterYDir) parameters[0]).up)) {
stepY = -1;
} else {
stepY = 1;
}
int center = 4;
if (parameters.length >= 2 && parameters[1] != null) {
center = ((PatternParameterCenter) parameters[1]).getDirection();
}
modifiers[0] = (MODIFIERS[center] >> 12) & 1;
modifiers[1] = (MODIFIERS[center] >> 8) & 1;
modifiers[2] = (MODIFIERS[center] >> 4) & 1;
modifiers[3] = (MODIFIERS[center]) & 1;
if (stepY == 1) {
height = yMin;
} else {
height = yMax;
}
while (step <= xSize / 2 && step <= zSize / 2 && height >= yMin && height <= yMax) {
for (int x = xMin + step; x <= xMax - step; ++x) {
for (int z = zMin + step; z <= zMax - step; ++z) {
bpt.contents [x - xMin][height - yMin][z - zMin] = new SchematicMask(true);
int x1 = xMin;
int x2 = xMax;
int z1 = zMin;
int z2 = zMax;
while (height >= yMin && height <= yMax) {
for (int x = x1; x <= x2; ++x) {
for (int z = z1; z <= z2; ++z) {
bpt.contents[x - xMin][height - yMin][z - zMin] = new SchematicMask(true);
}
}
step++;
x1 += modifiers[0];
x2 -= modifiers[1];
z1 += modifiers[2];
z2 -= modifiers[3];
height += stepY;
if (x1 > x2 || z1 > z2) {
break;
}
}
return bpt;

View file

@ -16,12 +16,6 @@ import buildcraft.core.blueprints.Template;
public class PatternStairs extends FillerPattern {
private int param2 = 0;
// TODO: These parameters need to be settable from the filler
private int param3 = 0;
private int param4 = 0;
public PatternStairs() {
super("stairs");
}
@ -56,10 +50,7 @@ public class PatternStairs extends FillerPattern {
Template template = new Template (box.sizeX(), box.sizeY(), box.sizeZ());
int height;
int heightStep;
int dimX = 0;
int dimZ = 0;
int height, heightStep;
if (parameters.length >= 1 && parameters[0] != null && !(((PatternParameterYDir) parameters[0]).up)) {
height = Math.max(yMin, yMax - Math.max(xMax, zMax));
@ -69,19 +60,13 @@ public class PatternStairs extends FillerPattern {
heightStep = -1;
}
int param2 = 0;
if (parameters.length >= 2 && parameters[1] != null) {
param2 = ((PatternParameterXZDir) parameters[1]).getDirection();
} else {
param2 = 0;
}
int kind = 0;
int[] steps = new int[] {0, 0, 0, 0};
int x = 0, z = 0;
int stepDiagX = 0, stepDiagZ = 0;
if (param2 == 0) {
steps[0] = 1;
} else if (param2 == 1) {
@ -90,38 +75,6 @@ public class PatternStairs extends FillerPattern {
steps[2] = 1;
} else if (param2 == 3) {
steps[3] = 1;
} else {
kind = 1;
if (param3 == 0) {
x = xMin;
} else if (param3 == 1) {
x = xMax;
} else if (param3 == 2) {
// no change
}
if (param4 == 0) {
z = zMin;
} else if (param4 == 1) {
z = zMax;
} else if (param4 == 2) {
// no change
}
if (heightStep == 1) {
stepDiagX = -1;
dimX = sizeX - 1;
stepDiagZ = -1;
dimZ = sizeZ - 1;
} else {
stepDiagX = 1;
dimX = 0;
stepDiagZ = 1;
dimZ = 0;
}
}
int x1 = xMin, x2 = xMax, z1 = zMin, z2 = zMax;
@ -146,62 +99,15 @@ public class PatternStairs extends FillerPattern {
z1 = z2;
}
if (kind == 0) {
while (x2 - x1 + 1 > 0 && z2 - z1 + 1 > 0 && x2 - x1 < sizeX && z2 - z1 < sizeZ && height >= yMin && height <= yMax) {
fill(x1, height, z1, x2, height, z2, template);
while (x2 - x1 + 1 > 0 && z2 - z1 + 1 > 0 && x2 - x1 < sizeX && z2 - z1 < sizeZ && height >= yMin && height <= yMax) {
fill(x1, height, z1, x2, height, z2, template);
x2 += steps[0];
x1 -= steps[1];
z2 += steps[2];
z1 -= steps[3];
x2 += steps[0];
x1 -= steps[1];
z2 += steps[2];
z1 -= steps[3];
height += heightStep;
}
} else if (kind == 1) {
while (dimX >= 0 && dimX < sizeX && dimZ >= 0 && dimZ < sizeZ && height >= yMin && height <= yMax) {
if (heightStep == 1) {
if (param3 == 1) {
x1 = x - sizeX + 1;
x2 = x1 + dimX;
} else {
x2 = x + sizeX - 1;
x1 = x2 - dimX;
}
if (param4 == 1) {
z1 = z - sizeZ + 1;
z2 = z1 + dimZ;
} else {
z2 = z + sizeZ - 1;
z1 = z2 - dimZ;
}
} else if (heightStep == -1) {
if (param3 == 0) {
x1 = x;
x2 = x1 + dimX;
} else {
x2 = x;
x1 = x2 - dimX;
}
if (param3 == 1) {
z1 = z;
z2 = z1 + dimZ;
} else {
z2 = z;
z1 = z2 - dimZ;
}
}
fill(x1, height, z1, x2, height, z2, template);
dimX += stepDiagX;
dimZ += stepDiagZ;
height += heightStep;
}
height += heightStep;
}
return template;