mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 05:50:08 +00:00
Implement structure pulldown offset
This commit is contained in:
1 parent
3628b690e8
commit
d5705bbcb9
2 files changed
+22
-15
No files matched your search
@@ -76,6 +76,7 @@ public class Structure implements Serializable {
|
|||||||
BlockData d = b.getBlockData();
|
BlockData d = b.getBlockData();
|
||||||
boolean useState = true;
|
boolean useState = true;
|
||||||
StructureContainedBlock.Pull pull = StructureContainedBlock.Pull.NONE;
|
StructureContainedBlock.Pull pull = StructureContainedBlock.Pull.NONE;
|
||||||
|
int pullOffset = 0;
|
||||||
StructureSpawnRequirement requirement = StructureSpawnRequirement.BLANK;
|
StructureSpawnRequirement requirement = StructureSpawnRequirement.BLANK;
|
||||||
if(state instanceof Sign) { // Magic sign stuff
|
if(state instanceof Sign) { // Magic sign stuff
|
||||||
Sign s = (Sign) b.getState();
|
Sign s = (Sign) b.getState();
|
||||||
@@ -96,7 +97,8 @@ public class Structure implements Serializable {
|
|||||||
}
|
}
|
||||||
} else if(s.getLine(1).startsWith("[PULL=") && s.getLine(1).endsWith("]")) {
|
} else if(s.getLine(1).startsWith("[PULL=") && s.getLine(1).endsWith("]")) {
|
||||||
String og = s.getLine(1);
|
String og = s.getLine(1);
|
||||||
String spawn = og.substring(og.indexOf("=")+1, og.length()-1);
|
String spawn = og.substring(og.indexOf("=")+1, og.indexOf("_"));
|
||||||
|
pullOffset = Integer.parseInt(og.substring(og.indexOf("_")+1, og.length()-1));
|
||||||
try {
|
try {
|
||||||
pull = StructureContainedBlock.Pull.valueOf(spawn);
|
pull = StructureContainedBlock.Pull.valueOf(spawn);
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
@@ -108,7 +110,7 @@ public class Structure implements Serializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StructureContainedBlock block = new StructureContainedBlock(x, y, z, useState ? state : null, d, requirement, pull);
|
StructureContainedBlock block = new StructureContainedBlock(x, y, z, useState ? state : null, d, requirement, pull, pullOffset);
|
||||||
if(state instanceof BlockInventoryHolder) {
|
if(state instanceof BlockInventoryHolder) {
|
||||||
inventories.add(new StructureContainedInventory(((BlockInventoryHolder) state).getInventory(), block));
|
inventories.add(new StructureContainedInventory(((BlockInventoryHolder) state).getInventory(), block));
|
||||||
}
|
}
|
||||||
@@ -179,25 +181,23 @@ public class Structure implements Serializable {
|
|||||||
BlockData data = block.getBlockData().clone();
|
BlockData data = block.getBlockData().clone();
|
||||||
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());
|
Location loc = origin.clone().add(block.getX(), block.getY(), block.getZ());
|
||||||
main: do {
|
Block worldBlock = loc.getBlock();
|
||||||
worldBlock = loc.getBlock();
|
main: while(worldBlock.isEmpty()) {
|
||||||
if(block.getPull() == null) break;
|
if(block.getPull() == null) break;
|
||||||
empty = worldBlock.isEmpty();
|
|
||||||
switch(block.getPull()) {
|
switch(block.getPull()) {
|
||||||
case UP:
|
case UP:
|
||||||
loc.add(0, 1, 0);
|
worldBlock = worldBlock.getRelative(BlockFace.UP);
|
||||||
break;
|
break;
|
||||||
case DOWN:
|
case DOWN:
|
||||||
loc.subtract(0, 1, 0);
|
worldBlock = worldBlock.getRelative(BlockFace.DOWN);
|
||||||
break;
|
break;
|
||||||
case NONE: break main;
|
default: break main;
|
||||||
}
|
}
|
||||||
if(loc.getBlockY() > 255 || loc.getBlockY() < 0) return;
|
if(loc.getBlockY() > 255 || loc.getBlockY() < 0) return;
|
||||||
} while(empty);
|
}
|
||||||
|
int offset = block.getPullOffset();
|
||||||
|
if(offset != 0) worldBlock = worldBlock.getRelative((offset > 0) ? BlockFace.UP : BlockFace.DOWN, Math.abs(offset));
|
||||||
|
|
||||||
if(data instanceof Rotatable) {
|
if(data instanceof Rotatable) {
|
||||||
BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r);
|
BlockFace rt = getRotatedFace(((Rotatable) data).getRotation(), r);
|
||||||
@@ -251,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(), b.getPull()));
|
exec.accept(new StructureContainedBlock(x - getStructureInfo().getCenterX(), y, z - getStructureInfo().getCenterZ(), b.getState(), b.getBlockData(), b.getRequirement(), b.getPull(), b.getPullOffset()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,12 +14,13 @@ public class StructureContainedBlock implements Serializable {
|
|||||||
private final SerializableBlockData bl;
|
private final SerializableBlockData bl;
|
||||||
private transient BlockData data;
|
private transient BlockData data;
|
||||||
private final Pull pull;
|
private final Pull pull;
|
||||||
|
private final int pullOffset;
|
||||||
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, Pull pull) {
|
public StructureContainedBlock(int x, int y, int z, BlockState state, BlockData d, StructureSpawnRequirement spawn, Pull pull, int pullOffset) {
|
||||||
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;
|
||||||
@@ -29,8 +30,9 @@ public class StructureContainedBlock implements Serializable {
|
|||||||
this.bl = new SerializableBlockData(d);
|
this.bl = new SerializableBlockData(d);
|
||||||
this.requirement = spawn;
|
this.requirement = spawn;
|
||||||
this.pull = pull;
|
this.pull = pull;
|
||||||
|
this.pullOffset = pullOffset;
|
||||||
}
|
}
|
||||||
public StructureContainedBlock(int x, int y, int z, SerializableBlockState state, BlockData d, StructureSpawnRequirement spawn, Pull pull) {
|
public StructureContainedBlock(int x, int y, int z, SerializableBlockState state, BlockData d, StructureSpawnRequirement spawn, Pull pull, int pullOffset) {
|
||||||
if(state instanceof SerializableSign) {
|
if(state instanceof SerializableSign) {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
} else this.state = null;
|
} else this.state = null;
|
||||||
@@ -40,6 +42,7 @@ public class StructureContainedBlock implements Serializable {
|
|||||||
this.bl = new SerializableBlockData(d);
|
this.bl = new SerializableBlockData(d);
|
||||||
this.requirement = spawn;
|
this.requirement = spawn;
|
||||||
this.pull = pull;
|
this.pull = pull;
|
||||||
|
this.pullOffset = pullOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructureSpawnRequirement getRequirement() {
|
public StructureSpawnRequirement getRequirement() {
|
||||||
@@ -69,6 +72,10 @@ public class StructureContainedBlock implements Serializable {
|
|||||||
return pull;
|
return pull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPullOffset() {
|
||||||
|
return pullOffset;
|
||||||
|
}
|
||||||
|
|
||||||
public SerializableBlockState getState() {
|
public SerializableBlockState getState() {
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user