mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-08-30 05:40:34 +00:00
Add block pulldown/up to structures
This commit is contained in:
@@ -75,8 +75,9 @@ public class Structure implements Serializable {
|
|||||||
BlockState state = b.getState();
|
BlockState state = b.getState();
|
||||||
BlockData d = b.getBlockData();
|
BlockData d = b.getBlockData();
|
||||||
boolean useState = true;
|
boolean useState = true;
|
||||||
|
StructureContainedBlock.Pull pull = StructureContainedBlock.Pull.NONE;
|
||||||
StructureSpawnRequirement requirement = StructureSpawnRequirement.BLANK;
|
StructureSpawnRequirement requirement = StructureSpawnRequirement.BLANK;
|
||||||
if(state instanceof Sign) {
|
if(state instanceof Sign) { // Magic sign stuff
|
||||||
Sign s = (Sign) b.getState();
|
Sign s = (Sign) b.getState();
|
||||||
if(s.getLine(0).equals("[TERRA]")) {
|
if(s.getLine(0).equals("[TERRA]")) {
|
||||||
try {
|
try {
|
||||||
@@ -93,13 +94,21 @@ public class Structure implements Serializable {
|
|||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
throw new InitializationException("Invalid spawn type: " + spawn);
|
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) {
|
} catch(IllegalArgumentException e) {
|
||||||
throw new InitializationException("Invalid Block Data on sign: \"" + s.getLine(2) + s.getLine(3) + "\"");
|
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) {
|
if(state instanceof BlockInventoryHolder) {
|
||||||
inventories.add(new StructureContainedInventory(((BlockInventoryHolder) state).getInventory(), block));
|
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) {
|
private void pasteBlock(StructureContainedBlock block, Location origin, Rotation r) {
|
||||||
BlockData data = block.getBlockData().clone();
|
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)) {
|
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) {
|
if(data instanceof Rotatable) {
|
||||||
BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r);
|
BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r);
|
||||||
((Rotatable) data).setRotation(rt);
|
((Rotatable) data).setRotation(rt);
|
||||||
@@ -223,7 +251,7 @@ public class Structure implements Serializable {
|
|||||||
c.add(new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ()));
|
c.add(new Vector2(structureInfo.getCenterX(), structureInfo.getCenterZ()));
|
||||||
if(isInStructure((int) c.getX(), y, (int) c.getZ())) {
|
if(isInStructure((int) c.getX(), y, (int) c.getZ())) {
|
||||||
StructureContainedBlock b = structure[(int) c.getX()][(int) c.getZ()][y];
|
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()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,13 @@ public class StructureContainedBlock implements Serializable {
|
|||||||
public static final long serialVersionUID = 6143969483382710947L;
|
public static final long serialVersionUID = 6143969483382710947L;
|
||||||
private final SerializableBlockData bl;
|
private final SerializableBlockData bl;
|
||||||
private transient BlockData data;
|
private transient BlockData data;
|
||||||
|
private final Pull pull;
|
||||||
private final int x;
|
private final int x;
|
||||||
private final int y;
|
private final int y;
|
||||||
private final int z;
|
private final int z;
|
||||||
private final SerializableBlockState state;
|
private final SerializableBlockState state;
|
||||||
private final StructureSpawnRequirement requirement;
|
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) {
|
if(state instanceof Sign) {
|
||||||
this.state = new SerializableSign((org.bukkit.block.Sign) state);
|
this.state = new SerializableSign((org.bukkit.block.Sign) state);
|
||||||
} else this.state = null;
|
} else this.state = null;
|
||||||
@@ -27,8 +28,9 @@ public class StructureContainedBlock implements Serializable {
|
|||||||
this.z = z;
|
this.z = z;
|
||||||
this.bl = new SerializableBlockData(d);
|
this.bl = new SerializableBlockData(d);
|
||||||
this.requirement = spawn;
|
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) {
|
if(state instanceof SerializableSign) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
} else this.state = null;
|
} else this.state = null;
|
||||||
@@ -37,6 +39,7 @@ public class StructureContainedBlock implements Serializable {
|
|||||||
this.z = z;
|
this.z = z;
|
||||||
this.bl = new SerializableBlockData(d);
|
this.bl = new SerializableBlockData(d);
|
||||||
this.requirement = spawn;
|
this.requirement = spawn;
|
||||||
|
this.pull = pull;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructureSpawnRequirement getRequirement() {
|
public StructureSpawnRequirement getRequirement() {
|
||||||
@@ -62,8 +65,15 @@ public class StructureContainedBlock implements Serializable {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pull getPull() {
|
||||||
|
return pull;
|
||||||
|
}
|
||||||
|
|
||||||
public SerializableBlockState getState() {
|
public SerializableBlockState getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Pull {
|
||||||
|
UP, NONE, DOWN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user