Add block pulldown/up to structures

This commit is contained in:
dfsek
2020-10-13 16:36:51 -07:00
parent 42b012b36d
commit 3628b690e8
2 changed files with 45 additions and 7 deletions

View File

@@ -75,8 +75,9 @@ public class Structure implements Serializable {
BlockState state = b.getState();
BlockData d = b.getBlockData();
boolean useState = true;
StructureContainedBlock.Pull pull = StructureContainedBlock.Pull.NONE;
StructureSpawnRequirement requirement = StructureSpawnRequirement.BLANK;
if(state instanceof Sign) {
if(state instanceof Sign) { // Magic sign stuff
Sign s = (Sign) b.getState();
if(s.getLine(0).equals("[TERRA]")) {
try {
@@ -93,13 +94,21 @@ public class Structure implements Serializable {
} catch(IllegalArgumentException e) {
throw new InitializationException("Invalid spawn type: " + spawn);
}
} else if(s.getLine(1).startsWith("[PULL=") && s.getLine(1).endsWith("]")) {
String og = s.getLine(1);
String spawn = og.substring(og.indexOf("=")+1, og.length()-1);
try {
pull = StructureContainedBlock.Pull.valueOf(spawn);
} catch(IllegalArgumentException e) {
throw new InitializationException("Invalid pull type: " + spawn);
}
}
} catch(IllegalArgumentException e) {
throw new InitializationException("Invalid Block Data on sign: \"" + s.getLine(2) + s.getLine(3) + "\"");
}
}
}
StructureContainedBlock block = new StructureContainedBlock(x, y, z, useState ? state : null, d, requirement);
StructureContainedBlock block = new StructureContainedBlock(x, y, z, useState ? state : null, d, requirement, pull);
if(state instanceof BlockInventoryHolder) {
inventories.add(new StructureContainedInventory(((BlockInventoryHolder) state).getInventory(), block));
}
@@ -168,9 +177,28 @@ public class Structure implements Serializable {
*/
private void pasteBlock(StructureContainedBlock block, Location origin, Rotation r) {
BlockData data = block.getBlockData().clone();
Location loc = origin.clone().add(block.getX(), block.getY(), block.getZ());
Block worldBlock = loc.getBlock();
if(!data.getMaterial().equals(Material.STRUCTURE_VOID)) {
Block worldBlock;
boolean empty;
Location loc = origin.clone().add(block.getX(), block.getY(), block.getZ());
main: do {
worldBlock = loc.getBlock();
if(block.getPull() == null) break;
empty = worldBlock.isEmpty();
switch(block.getPull()) {
case UP:
loc.add(0, 1, 0);
break;
case DOWN:
loc.subtract(0, 1, 0);
break;
case NONE: break main;
}
if(loc.getBlockY() > 255 || loc.getBlockY() < 0) return;
} while(empty);
if(data instanceof Rotatable) {
BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r);
((Rotatable) data).setRotation(rt);
@@ -223,7 +251,7 @@ public class Structure implements Serializable {
c.add(new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ()));
if(isInStructure((int) c.getX(), y, (int) c.getZ())) {
StructureContainedBlock b = structure[(int) c.getX()][(int) c.getZ()][y];
exec.accept(new StructureContainedBlock(x - getStructureInfo().getCenterX(), y, z - getStructureInfo().getCenterZ(), b.getState(), b.getBlockData(), b.getRequirement()));
exec.accept(new StructureContainedBlock(x - getStructureInfo().getCenterX(), y, z - getStructureInfo().getCenterZ(), b.getState(), b.getBlockData(), b.getRequirement(), b.getPull()));
}
}
}

View File

@@ -13,12 +13,13 @@ public class StructureContainedBlock implements Serializable {
public static final long serialVersionUID = 6143969483382710947L;
private final SerializableBlockData bl;
private transient BlockData data;
private final Pull pull;
private final int x;
private final int y;
private final int z;
private final SerializableBlockState state;
private final StructureSpawnRequirement requirement;
public StructureContainedBlock(int x, int y, int z, BlockState state, BlockData d, StructureSpawnRequirement spawn) {
public StructureContainedBlock(int x, int y, int z, BlockState state, BlockData d, StructureSpawnRequirement spawn, Pull pull) {
if(state instanceof Sign) {
this.state = new SerializableSign((org.bukkit.block.Sign) state);
} else this.state = null;
@@ -27,8 +28,9 @@ public class StructureContainedBlock implements Serializable {
this.z = z;
this.bl = new SerializableBlockData(d);
this.requirement = spawn;
this.pull = pull;
}
public StructureContainedBlock(int x, int y, int z, SerializableBlockState state, BlockData d, StructureSpawnRequirement spawn) {
public StructureContainedBlock(int x, int y, int z, SerializableBlockState state, BlockData d, StructureSpawnRequirement spawn, Pull pull) {
if(state instanceof SerializableSign) {
this.state = state;
} else this.state = null;
@@ -37,6 +39,7 @@ public class StructureContainedBlock implements Serializable {
this.z = z;
this.bl = new SerializableBlockData(d);
this.requirement = spawn;
this.pull = pull;
}
public StructureSpawnRequirement getRequirement() {
@@ -62,8 +65,15 @@ public class StructureContainedBlock implements Serializable {
return data;
}
public Pull getPull() {
return pull;
}
public SerializableBlockState getState() {
return state;
}
public enum Pull {
UP, NONE, DOWN;
}
}