optimize blueprint array, add hollow option to cylinders, move pattern icons to items

This commit is contained in:
asiekierka 2015-06-15 13:04:08 +02:00
parent b6bac2c714
commit 0815e5f118
29 changed files with 229 additions and 75 deletions

View file

@ -166,6 +166,8 @@ fillerpattern.stairs=Stairs
fillerpattern.box=Box
fillerpattern.cylinder=Cylinder
fillerpattern.frame=Frame
fillerpattern.parameter.hollow=Hollow
fillerpattern.parameter.filled=Filled
fluid.oil=Oil
fluid.fuel=Fuel

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 B

View file

@ -1,10 +1,11 @@
Additions:
* New filler parameters: Center for Pyramids and Direction for Stairs (asie)
* New filler parameters: Hollow for Cylinders, Center for Pyramids and Direction for Stairs (asie)
* Support for inventory Minecarts in the obsidian pipe - partially a bugfix (asie)
Improvements:
* Optimizations to Builder/Filler code (asie)
* Tweaks to water spring generation (asie)
Bugs fixed:
@ -16,6 +17,6 @@ Bugs fixed:
* [#2796] Invalid height for stairs in Filler (asie)
* [#2792] Obsidian pipes not using up energy for items (asie)
* Fix buckets in stripes pipes not working with custom air blocks (asie)
* Fix filler pattern icon render in gates (asie)
* Fix stripes pipes eating unplaced blocks in a large stack (asie)
* Fix tooltip rendering in filler GUI (asie)

View file

@ -659,10 +659,6 @@ public class BuildCraftBuilders extends BuildCraftMod {
@SideOnly(Side.CLIENT)
public void loadTextures(TextureStitchEvent.Pre evt) {
if (evt.map.getTextureType() == 0) {
for (FillerPattern pattern : FillerPattern.patterns.values()) {
pattern.registerIcons(evt.map);
}
TextureMap terrainTextures = evt.map;
BuilderProxyClient.drillTexture = terrainTextures.registerIcon("buildcraftbuilders:machineBlock/drill");
BuilderProxyClient.drillHeadTexture = terrainTextures.registerIcon("buildcraftbuilders:machineBlock/drill_head");

View file

@ -94,6 +94,7 @@ import buildcraft.core.TickHandlerCore;
import buildcraft.core.TileEngineWood;
import buildcraft.core.Version;
import buildcraft.core.blueprints.SchematicRegistry;
import buildcraft.core.builders.patterns.FillerPattern;
import buildcraft.core.builders.patterns.FillerRegistry;
import buildcraft.core.builders.patterns.PatternBox;
import buildcraft.core.builders.patterns.PatternClear;
@ -103,6 +104,7 @@ 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.PatternParameterHollow;
import buildcraft.core.builders.patterns.PatternParameterXZDir;
import buildcraft.core.builders.patterns.PatternParameterYDir;
import buildcraft.core.builders.patterns.PatternPyramid;
@ -450,6 +452,7 @@ public class BuildCraftCore extends BuildCraftMod {
StatementManager.registerParameterClass(PatternParameterYDir.class);
StatementManager.registerParameterClass(PatternParameterXZDir.class);
StatementManager.registerParameterClass(PatternParameterCenter.class);
StatementManager.registerParameterClass(PatternParameterHollow.class);
}
@Mod.EventHandler
@ -532,6 +535,10 @@ public class BuildCraftCore extends BuildCraftMod {
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void textureHook(TextureStitchEvent.Pre event) {
for (FillerPattern pattern : FillerPattern.patterns.values()) {
pattern.registerIcons(event.map);
}
if (event.map.getTextureType() == 1) {
iconProvider = new CoreIconProvider();
iconProvider.registerIcons(event.map);

View file

@ -34,7 +34,7 @@ public class ContainerFiller extends BuildCraftContainer {
@SideOnly(Side.CLIENT)
@Override
public void draw(GuiBuildCraft gui, int guiX, int guiY, int mouseX, int mouseY) {
gui.bindTexture(TextureMap.locationBlocksTexture);
gui.bindTexture(TextureMap.locationItemsTexture);
gui.drawTexturedModelRectFromIcon(guiX + x, guiY + y, tile.currentPattern.getIcon(), 16, 16);
}
}

View file

@ -38,11 +38,27 @@ public class ActionFiller extends BCStatement implements IActionExternal {
return pattern.getIcon();
}
@Override
public int minParameters() {
return pattern.minParameters();
}
@Override
public int maxParameters() {
return pattern.maxParameters();
}
@Override
public IStatementParameter createParameter(int index) {
return pattern.createParameter(index);
}
@Override
public void actionActivate(TileEntity target, ForgeDirection side,
IStatementContainer source, IStatementParameter[] parameters) {
if (target instanceof TileFiller) {
((TileFiller) target).setPattern(pattern);
((TileFiller) target).patternParameters = parameters;
}
}
}

View file

@ -23,6 +23,7 @@ import buildcraft.api.blueprints.BuildingPermission;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.SchematicBlock;
import buildcraft.api.blueprints.SchematicBlockBase;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.blueprints.Translation;
import buildcraft.api.core.BCLog;
@ -103,7 +104,7 @@ public class Blueprint extends BlueprintBase {
try {
slot.initializeFromObjectAt(context, x, y, z);
slot.storeRequirements(context, x, y, z);
contents[posX][posY][posZ] = slot;
put(posX, posY, posZ, slot);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
@ -119,7 +120,7 @@ public class Blueprint extends BlueprintBase {
buildingPermission = BuildingPermission.CREATIVE_ONLY;
}
} else {
contents[posX][posY][posZ] = null;
put(posX, posY, posZ, null);
}
break;
case NONE:
@ -174,11 +175,12 @@ public class Blueprint extends BlueprintBase {
for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
SchematicBlockBase schematic = get(x, y, z);
NBTTagCompound cpt = new NBTTagCompound();
if (contents [x][y][z] != null) {
contents[x][y][z].idsToBlueprint(mapping);
contents[x][y][z].writeSchematicToNBT(cpt, mapping);
if (schematic != null) {
schematic.idsToBlueprint(mapping);
schematic.writeSchematicToNBT(cpt, mapping);
}
nbtContents.appendTag(cpt);
@ -231,14 +233,14 @@ public class Blueprint extends BlueprintBase {
if (block != null) {
int meta = cpt.getInteger("blockMeta");
contents[x][y][z] = SchematicRegistry.INSTANCE.createSchematicBlock(block, meta);
if (contents[x][y][z] != null) {
contents[x][y][z].readSchematicFromNBT(cpt, mapping);
SchematicBlockBase schematic = SchematicRegistry.INSTANCE.createSchematicBlock(block, meta);
if (schematic != null) {
schematic.readSchematicFromNBT(cpt, mapping);
if (!contents[x][y][z].doNotUse()) {
contents[x][y][z].idsToWorld(mapping);
if (!schematic.doNotUse()) {
schematic.idsToWorld(mapping);
switch (contents[x][y][z].getBuildingPermission()) {
switch (schematic.getBuildingPermission()) {
case ALL:
break;
case CREATIVE_ONLY:
@ -251,16 +253,17 @@ public class Blueprint extends BlueprintBase {
break;
}
} else {
contents[x][y][z] = null;
schematic = null;
isComplete = false;
}
}
put(x, y, z, schematic);
} else {
contents[x][y][z] = null;
put(x, y, z, null);
isComplete = false;
}
} else {
contents[x][y][z] = null;
put(x, y, z, null);
}
}
}

View file

@ -35,7 +35,6 @@ public abstract class BlueprintBase {
public ArrayList<NBTTagCompound> subBlueprintsNBT = new ArrayList<NBTTagCompound>();
public SchematicBlockBase[][][] contents;
public int anchorX, anchorY, anchorZ;
public int sizeX, sizeY, sizeZ;
public LibraryId id = new LibraryId();
@ -46,6 +45,7 @@ public abstract class BlueprintBase {
public boolean isComplete = true;
protected MappingRegistry mapping = new MappingRegistry();
protected SchematicBlockBase[] contents;
private ComputeDataThread computeData;
private byte [] data;
@ -55,7 +55,7 @@ public abstract class BlueprintBase {
}
public BlueprintBase(int sizeX, int sizeY, int sizeZ) {
contents = new SchematicBlockBase[sizeX][sizeY][sizeZ];
contents = new SchematicBlockBase[sizeX * sizeY * sizeZ];
this.sizeX = sizeX;
this.sizeY = sizeY;
@ -66,41 +66,46 @@ public abstract class BlueprintBase {
anchorZ = 0;
}
private int toArrayPos(int x, int y, int z) {
return (y * sizeZ + z) * sizeX + x;
}
public SchematicBlockBase get(int x, int y, int z) {
return contents[(y * sizeZ + z) * sizeX + x];
}
public void put(int x, int y, int z, SchematicBlockBase s) {
contents[(y * sizeZ + z) * sizeX + x] = s;
}
public void translateToBlueprint(Translation transform) {
for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
if (contents [x][y][z] != null) {
contents[x][y][z].translateToBlueprint(transform);
}
}
for (int i = 0; i < contents.length; i++) {
if (contents[i] != null) {
contents[i].translateToBlueprint(transform);
}
}
}
public void translateToWorld(Translation transform) {
for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
if (contents [x][y][z] != null) {
contents[x][y][z].translateToWorld(transform);
}
}
for (int i = 0; i < contents.length; i++) {
if (contents[i] != null) {
contents[i].translateToWorld(transform);
}
}
}
public void rotateLeft(BptContext context) {
SchematicBlockBase[][][] newContents = new SchematicBlockBase[sizeZ][sizeY][sizeX];
SchematicBlockBase[] newContents = new SchematicBlockBase[sizeZ * sizeY * sizeX];
for (int x = 0; x < sizeZ; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeX; ++z) {
newContents[x][y][z] = contents[z][y][(sizeZ - 1) - x];
int pos = toArrayPos(x, y, z);
newContents[pos] = contents[toArrayPos(z, y, (sizeZ - 1) - x)];
if (newContents[x][y][z] != null) {
if (newContents[pos] != null) {
try {
newContents[x][y][z].rotateLeft(context);
newContents[pos].rotateLeft(context);
} catch (Throwable t) {
// Defensive code against errors in implementers
t.printStackTrace();
@ -217,7 +222,7 @@ public abstract class BlueprintBase {
excavate = true;
}
contents = new SchematicBlockBase[sizeX][sizeY][sizeZ];
contents = new SchematicBlockBase[sizeX * sizeY * sizeZ];
try {
loadContents(nbt);

View file

@ -87,7 +87,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
}
if (!isLocationUsed(xCoord, yCoord, zCoord)) {
SchematicBlock slot = (SchematicBlock) blueprint.contents[i][j][k];
SchematicBlock slot = (SchematicBlock) blueprint.get(i, j, k);
if (slot == null && !blueprint.excavate) {
continue;
@ -128,7 +128,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
int yCoord = j + y - blueprint.anchorY;
int zCoord = k + z - blueprint.anchorZ;
SchematicBlock slot = (SchematicBlock) blueprint.contents[i][j][k];
SchematicBlock slot = (SchematicBlock) blueprint.get(i, j, k);
if (slot == null || yCoord < 0 || yCoord >= context.world.getHeight()) {
continue;

View file

@ -50,7 +50,7 @@ public class BptBuilderTemplate extends BptBuilderBase {
continue;
}
SchematicBlockBase slot = blueprint.contents[i][j][k];
SchematicBlockBase slot = blueprint.get(i, j, k);
if (slot == null && !isLocationUsed(xCoord, yCoord, zCoord)) {
BuildingSlotBlock b = new BuildingSlotBlock();
@ -80,7 +80,7 @@ public class BptBuilderTemplate extends BptBuilderBase {
continue;
}
SchematicBlockBase slot = blueprint.contents[i][j][k];
SchematicBlockBase slot = blueprint.get(i, j, k);
if (slot != null && !isLocationUsed(xCoord, yCoord, zCoord)) {
BuildingSlotBlock b = new BuildingSlotBlock();

View file

@ -40,7 +40,7 @@ public class Template extends BlueprintBase {
int posZ = (int) (z - context.surroundingBox().pMin().z);
if (!BuildCraftAPI.isSoftBlock(anchorTile.getWorldObj(), x, y, z)) {
contents[posX][posY][posZ] = new SchematicMask(true);
put(posX, posY, posZ, new SchematicMask(true));
}
}
@ -56,7 +56,7 @@ public class Template extends BlueprintBase {
for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
data [ind] = (byte) ((contents[x][y][z] == null) ? 0 : 1);
data [ind] = (byte) ((get(x, y, z) == null) ? 0 : 1);
ind++;
}
}
@ -74,7 +74,7 @@ public class Template extends BlueprintBase {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
if (data [ind] == 1) {
contents[x][y][z] = new SchematicMask(true);
put(x, y, z, new SchematicMask(true));
}
ind++;

View file

@ -13,6 +13,7 @@ import java.util.TreeMap;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.common.Loader;
@ -62,9 +63,14 @@ public abstract class FillerPattern implements IFillerPattern {
@Override
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraftcore:fillerPatterns/" + tag);
if (!(iconRegister instanceof TextureMap) || ((TextureMap) iconRegister).getTextureType() == 1) {
icon = iconRegister.registerIcon("buildcraftcore:fillerPatterns/" + tag);
}
if (Loader.isModLoaded("BuildCraft|Builders")) {
blockIcon = iconRegister.registerIcon("buildcraftbuilders:fillerBlockIcons/" + tag);
if (!(iconRegister instanceof TextureMap) || ((TextureMap) iconRegister).getTextureType() == 0) {
blockIcon = iconRegister.registerIcon("buildcraftbuilders:fillerBlockIcons/" + tag);
}
}
}
@ -103,7 +109,7 @@ public abstract class FillerPattern implements IFillerPattern {
for (int x = xMin; x <= xMax; ++x) {
for (int z = zMin; z <= zMax; ++z) {
if (isValid(x, y, z, template)) {
template.contents[x][y][z] = new SchematicMask(true);
template.put(x, y, z, new SchematicMask(true));
}
}
}
@ -120,7 +126,7 @@ public abstract class FillerPattern implements IFillerPattern {
for (int x = xMin; x <= xMax; ++x) {
for (int z = zMin; z <= zMax; ++z) {
if (isValid(x, y, z, template)) {
template.contents[x][y][z] = null;
template.put(x, y, z, null);
}
}
}
@ -137,7 +143,7 @@ public abstract class FillerPattern implements IFillerPattern {
for (int z = zMin; z <= zMax; ++z) {
for (int y = yMax; y >= yMin; --y) {
if (isValid(x, y, z, template)) {
template.contents [x][y][z] = new SchematicMask(true);
template.put(x, y, z, new SchematicMask(true));
}
}
}
@ -155,9 +161,9 @@ public abstract class FillerPattern implements IFillerPattern {
for (int x = 0; x < box.sizeX(); ++x) {
for (int y = 0; y < box.sizeY(); ++y) {
for (int z = 0; z < box.sizeZ(); ++z) {
if (tmpl.contents[x][y][z] != null) {
result.contents[x][y][z] = SchematicRegistry.INSTANCE
.createSchematicBlock(block, meta);
if (tmpl.get(x, y, z) != null) {
result.put(x, y, z, SchematicRegistry.INSTANCE
.createSchematicBlock(block, meta));
}
}

View file

@ -20,10 +20,25 @@ public class PatternCylinder extends FillerPattern {
super("cylinder");
}
@Override
public int maxParameters() {
return 1;
}
@Override
public int minParameters() {
return 1;
}
@Override
public IStatementParameter createParameter(int index) {
return new PatternParameterHollow(true);
}
@Override
public Template getTemplate(Box box, World world, IStatementParameter[] parameters) {
Template result = new Template (box.sizeX(), box.sizeY(), box.sizeZ());
boolean filled = parameters.length > 0 && ((PatternParameterHollow) parameters[0]).filled;
int xMin = 0;
int yMin = 0;
@ -59,8 +74,13 @@ public class PatternCylinder extends FillerPattern {
if (twoASquare > 0) {
while (stoppingX >= stoppingZ) {
fillFourColumns(xCenter, zCenter, dx, dz, xFix, zFix, yMin,
yMax, result);
if (filled) {
fillSquare(xCenter, zCenter, dx, dz, xFix, zFix, yMin,
yMax, result);
} else {
fillFourColumns(xCenter, zCenter, dx, dz, xFix, zFix, yMin,
yMax, result);
}
++dz;
stoppingZ += twoASquare;
@ -104,6 +124,36 @@ public class PatternCylinder extends FillerPattern {
return result;
}
private boolean fillSquare(int xCenter, int zCenter, int dx, int dz,
int xFix, int zFix, int yMin, int yMax, Template template) {
int x1, x2, z1, z2;
x1 = xCenter + dx + xFix;
z1 = zCenter + dz + zFix;
x2 = xCenter - dx;
z2 = zCenter + dz + zFix;
fill(x2, yMin, z2, x1, yMax, z1, template);
x1 = xCenter - dx;
z1 = zCenter - dz;
fill(x1, yMin, z1, x2, yMax, z2, template);
x2 = xCenter + dx + xFix;
z2 = zCenter - dz;
fill(x1, yMin, z1, x2, yMax, z2, template);
x1 = xCenter + dx + xFix;
z1 = zCenter + dz + zFix;
fill(x2, yMin, z2, x1, yMax, z1, template);
return true;
}
private boolean fillFourColumns(int xCenter, int zCenter, int dx, int dz,
int xFix, int zFix, int yMin, int yMax, Template template) {
int x, z;

View file

@ -37,7 +37,7 @@ public class PatternFlatten extends FillerPattern {
if (box.pMin().y > 0) {
for (int x = xMin; x <= xMax; ++x) {
for (int z = zMin; z <= zMax; ++z) {
bpt.contents[x - xMin][0][z - zMin] = new SchematicMask(true);
bpt.put(x - xMin, 0, z - zMin, new SchematicMask(true));
}
}
}

View file

@ -26,31 +26,27 @@ public class PatternFrame extends FillerPattern {
public Template getTemplate(Box box, World world, IStatementParameter[] parameters) {
Template template = new Template (box.sizeX(), box.sizeY(), box.sizeZ());
int xMin = 0;
int yMin = 0;
int zMin = 0;
int xMax = box.sizeX() - 1;
int yMax = box.sizeY() - 1;
int zMax = box.sizeZ() - 1;
for (int it = 0; it < 2; it++) {
int y = it * (box.sizeY() - 1);
for (int i = 0; i < template.sizeX; ++i) {
template.contents [i][it * (box.sizeY() - 1)][0] = new SchematicMask (true);
template.contents [i][it * (box.sizeY() - 1)][template.sizeZ - 1] = new SchematicMask (true);
template.put(i, y, 0, new SchematicMask(true));
template.put(i, y, zMax, new SchematicMask(true));
}
for (int k = 0; k < template.sizeZ; ++k) {
template.contents [0][it * (box.sizeY() - 1)][k] = new SchematicMask (true);
template.contents [template.sizeX - 1][it * (box.sizeY() - 1)][k] = new SchematicMask (true);
template.put(0, y, k, new SchematicMask(true));
template.put(xMax, y, k, new SchematicMask(true));
}
}
for (int h = 1; h < box.sizeY(); ++h) {
template.contents [0][h][0] = new SchematicMask (true);
template.contents [0][h][template.sizeZ - 1] = new SchematicMask (true);
template.contents [template.sizeX - 1][h][0] = new SchematicMask (true);
template.contents [template.sizeX - 1][h][template.sizeZ - 1] = new SchematicMask (true);
template.put(0, h, 0, new SchematicMask(true));
template.put(0, h, zMax, new SchematicMask(true));
template.put(xMax, h, 0, new SchematicMask(true));
template.put(xMax, h, zMax, new SchematicMask(true));
}
return template;

View file

@ -37,7 +37,7 @@ public class PatternHorizon extends FillerPattern {
if (box.sizeY() > 0) {
for (int x = xMin; x <= xMax; ++x) {
for (int z = zMin; z <= zMax; ++z) {
bpt.contents[x - xMin][0][z - zMin] = new SchematicMask(true);
bpt.put(x - xMin, 0, z - zMin, new SchematicMask(true));
}
}
}

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.lib.utils.StringUtils;
public class PatternParameterHollow implements IStatementParameter {
private static IIcon iconHollow, iconFilled;
public boolean filled = false;
public PatternParameterHollow() {
super();
}
public PatternParameterHollow(boolean hollow) {
this();
this.filled = !hollow;
}
@Override
public String getUniqueTag() {
return "buildcraft:fillerParameterHollow";
}
@Override
public IIcon getIcon() {
return filled ? iconFilled : iconHollow;
}
@Override
public ItemStack getItemStack() {
return null;
}
@Override
public void registerIcons(IIconRegister iconRegister) {
iconFilled = iconRegister.registerIcon("buildcraftcore:fillerParameters/filled");
iconHollow = iconRegister.registerIcon("buildcraftcore:fillerParameters/hollow");
}
@Override
public String getDescription() {
return StringUtils.localize("fillerpattern.parameter." + (filled ? "filled" : "hollow"));
}
@Override
public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse) {
filled = !filled;
}
@Override
public void readFromNBT(NBTTagCompound compound) {
filled = compound.getBoolean("filled");
}
@Override
public void writeToNBT(NBTTagCompound compound) {
compound.setBoolean("filled", filled);
}
@Override
public IStatementParameter rotateLeft() {
return this;
}
}

View file

@ -93,7 +93,7 @@ public class PatternPyramid extends FillerPattern {
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);
bpt.put(x - xMin, height - yMin, z - zMin, new SchematicMask(true));
}
}