fixed entity schematic building, part of #1565
This commit is contained in:
parent
b07d0b059d
commit
7bde6b7903
26 changed files with 140 additions and 34 deletions
|
@ -39,6 +39,15 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
*/
|
||||
public class Schematic {
|
||||
|
||||
/**
|
||||
* Return true if the block on the world correspond to the block stored in
|
||||
* the blueprint at the location given by the slot. By default, this
|
||||
* subprogram is permissive and doesn't take into account metadata.
|
||||
*/
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public final LinkedList<ItemStack> getRequirements(IBuilderContext context) {
|
||||
LinkedList<ItemStack> res = new LinkedList<ItemStack>();
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ public class SchematicBlock extends SchematicBlockBase implements Comparable<Sc
|
|||
* subprogram is permissive and doesn't take into account metadata.
|
||||
*/
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z) && meta == context.world().getBlockMetadata(x, y, z);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,15 +34,6 @@ package buildcraft.api.blueprints;
|
|||
*/
|
||||
public class SchematicBlockBase extends Schematic {
|
||||
|
||||
/**
|
||||
* Return true if the block on the world correspond to the block stored in
|
||||
* the blueprint at the location given by the slot. By default, this
|
||||
* subprogram is permissive and doesn't take into account metadata.
|
||||
*/
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeCompleted(IBuilderContext context, int x, int y, int z, double completed) {
|
||||
|
||||
}
|
||||
|
|
|
@ -145,4 +145,24 @@ public class SchematicEntity extends Schematic {
|
|||
|
||||
return nbttaglist;
|
||||
}
|
||||
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, CoordTransformation transform) {
|
||||
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
|
||||
Position newPosition = new Position(nbttaglist.func_150309_d(0),
|
||||
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
|
||||
|
||||
newPosition = transform.translate(newPosition);
|
||||
|
||||
for (Object o : context.world().loadedEntityList) {
|
||||
Entity e = (Entity) o;
|
||||
|
||||
Position existingPositon = new Position(e.posX, e.posY, e.posZ);
|
||||
|
||||
if (existingPositon.isClose (newPosition, 0.1F)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class SchematicMask extends SchematicBlockBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
if (isConcrete) {
|
||||
return !BlockUtil.isSoftBlock(context.world(), x, y, z);
|
||||
} else {
|
||||
|
|
|
@ -148,4 +148,18 @@ public class Position {
|
|||
return new Position(p.x < x ? x : p.x, p.y < y ? y : p.y, p.z < z ? z : p.z);
|
||||
}
|
||||
|
||||
public boolean isClose(Position newPosition, float f) {
|
||||
double dx = x - newPosition.x;
|
||||
double dy = y - newPosition.y;
|
||||
double dz = z - newPosition.z;
|
||||
|
||||
double sqrDis = dx * dx + dy * dy + dz * dz;
|
||||
|
||||
if (sqrDis > f * f) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ public class SchematicDirt extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
Block block = context.world().getBlock(x, y, z);
|
||||
|
||||
return block == Blocks.dirt || block == Blocks.grass || block == Blocks.farmland;
|
||||
|
|
|
@ -29,7 +29,7 @@ public class SchematicFarmland extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
Block block = context.world().getBlock(x, y, z);
|
||||
|
||||
return block == Blocks.farmland;
|
||||
|
|
|
@ -30,7 +30,7 @@ public class SchematicFluid extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
if (meta == 0) {
|
||||
return block == context.world().getBlock(x, y, z) && context.world().getBlockMetadata(x, y, z) == 0;
|
||||
} else {
|
||||
|
|
|
@ -29,7 +29,7 @@ public class SchematicGravel extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
Block block = context.world().getBlock(x, y, z);
|
||||
|
||||
return block == Blocks.gravel;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package buildcraft.builders.schematics;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityHanging;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -85,4 +86,30 @@ public class SchematicHanging extends SchematicEntity {
|
|||
storedRequirements [0] = new ItemStack(baseItem);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, CoordTransformation transform) {
|
||||
Position newPosition = new Position (cpt.getInteger("TileX"), cpt.getInteger("TileY"), cpt.getInteger("TileZ"));
|
||||
newPosition = transform.translate(newPosition);
|
||||
|
||||
int dir = cpt.getInteger("Direction");
|
||||
|
||||
for (Object o : context.world().loadedEntityList) {
|
||||
Entity e = (Entity) o;
|
||||
|
||||
if (e instanceof EntityHanging) {
|
||||
EntityHanging h = (EntityHanging) e;
|
||||
Position existingPositon = new Position(h.field_146063_b, h.field_146064_c, h.field_146062_d);
|
||||
|
||||
System.out.println ("EXPECTED POS" + newPosition + ", found " + existingPositon);
|
||||
System.out.println ("EXPECTED DIR" + dir + ", found " + ((EntityHanging) e).hangingDirection);
|
||||
|
||||
if (existingPositon.isClose(newPosition, 0.1F) && dir == ((EntityHanging) e).hangingDirection) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class SchematicIgnore extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public class SchematicIgnoreMeta extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
package buildcraft.builders.schematics;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityMinecart;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
@ -51,4 +52,32 @@ public class SchematicMinecart extends SchematicEntity {
|
|||
storedRequirements = new ItemStack [1];
|
||||
storedRequirements [0] = new ItemStack(baseItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, CoordTransformation transform) {
|
||||
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
|
||||
Position newPosition = new Position(nbttaglist.func_150309_d(0),
|
||||
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
|
||||
|
||||
newPosition.x += 0.5;
|
||||
newPosition.z += 0.5;
|
||||
|
||||
newPosition = transform.translate(newPosition);
|
||||
|
||||
for (Object o : context.world().loadedEntityList) {
|
||||
Entity e = (Entity) o;
|
||||
|
||||
Position existingPositon = new Position(e.posX, e.posY, e.posZ);
|
||||
|
||||
if (e instanceof EntityMinecart) {
|
||||
System.out.println ("found " + existingPositon + ", should be " + newPosition);
|
||||
if (existingPositon.isClose(newPosition, 0.1F)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public class SchematicPortal extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ public class SchematicPumpkin extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z);
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class SchematicRail extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ public class SchematicRotateMeta extends SchematicTile {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class SchematicSeeds extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return context.world().getBlock(x, y, z) == block;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ public class SchematicStairs extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z);
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public class SchematicStone extends SchematicBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
Block block = context.world().getBlock(x, y, z);
|
||||
|
||||
return block == Blocks.stone;
|
||||
|
|
|
@ -163,8 +163,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
|
||||
try {
|
||||
getNext = !slot.schematic.ignoreBuilding()
|
||||
&& !slot.schematic.isValid(context, slot.x, slot.y,
|
||||
slot.z);
|
||||
&& !slot.isAlreadyBuilt(context);
|
||||
} catch (Throwable t) {
|
||||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
|
@ -207,15 +206,19 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
TileAbstractBuilder builder, LinkedList<BuildingSlotEntity> list) {
|
||||
Iterator<BuildingSlotEntity> it = list.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
BuildingSlotEntity slot = it.next();
|
||||
|
||||
if (checkRequirements(builder, slot.schematic)) {
|
||||
useRequirements(builder, slot);
|
||||
if (slot.isAlreadyBuilt(context)) {
|
||||
it.remove();
|
||||
} else {
|
||||
if (checkRequirements(builder, slot.schematic)) {
|
||||
useRequirements(builder, slot);
|
||||
|
||||
iterator.remove();
|
||||
postProcessing.add(slot);
|
||||
return slot;
|
||||
it.remove();
|
||||
postProcessing.add(slot);
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,5 +45,7 @@ public abstract class BuildingSlot {
|
|||
stackConsumed.add (stack);
|
||||
}
|
||||
|
||||
public abstract boolean isAlreadyBuilt (IBuilderContext context);
|
||||
|
||||
public abstract Schematic getSchematic ();
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class BuildingSlotBlock extends BuildingSlot implements Comparable<Buildi
|
|||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
if (mode == Mode.ClearIfInvalid) {
|
||||
if (!getSchematic().isValid(context, x, y, z)) {
|
||||
if (!getSchematic().isAlreadyBuilt(context, x, y, z)) {
|
||||
context.world().setBlockToAir(x, y, z);
|
||||
}
|
||||
} else {
|
||||
|
@ -119,4 +119,9 @@ public class BuildingSlotBlock extends BuildingSlot implements Comparable<Buildi
|
|||
public void writeCompleted (IBuilderContext context, double complete) {
|
||||
getSchematic().writeCompleted(context, x, y, z, complete);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlreadyBuilt(IBuilderContext context) {
|
||||
return schematic.isAlreadyBuilt(context, x, y, z);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public class BuildingSlotEntity extends BuildingSlot {
|
|||
NBTTagList nbttaglist = schematic.cpt.getTagList("Pos", 6);
|
||||
Position pos = new Position(nbttaglist.func_150309_d(0),
|
||||
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
|
||||
|
||||
pos = transform.translate(pos);
|
||||
|
||||
return pos;
|
||||
|
@ -52,4 +53,9 @@ public class BuildingSlotEntity extends BuildingSlot {
|
|||
public SchematicEntity getSchematic() {
|
||||
return schematic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlreadyBuilt(IBuilderContext context) {
|
||||
return schematic.isAlreadyBuilt(context, transform);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import buildcraft.transport.TileGenericPipe.SideProperties;
|
|||
public class SchematicPipe extends SchematicTile {
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
|
||||
Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z);
|
||||
|
||||
if (BlockGenericPipe.isValid(pipe)) {
|
||||
|
|
Loading…
Add table
Reference in a new issue