This commit is contained in:
parent
1767ab23f8
commit
52a7fd3769
2 changed files with 127 additions and 0 deletions
108
src/main/java/net/pietru/cookie_utils/setups/areaFillSetup.java
Normal file
108
src/main/java/net/pietru/cookie_utils/setups/areaFillSetup.java
Normal file
|
@ -0,0 +1,108 @@
|
||||||
|
package net.pietru.cookie_utils.setups;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
import com.badlogic.gdx.utils.Queue;
|
||||||
|
import finalforeach.cosmicreach.blocks.BlockPosition;
|
||||||
|
import finalforeach.cosmicreach.blocks.BlockState;
|
||||||
|
import finalforeach.cosmicreach.entities.player.Player;
|
||||||
|
import finalforeach.cosmicreach.networking.server.ServerSingletons;
|
||||||
|
import finalforeach.cosmicreach.world.BlockSetter;
|
||||||
|
import finalforeach.cosmicreach.world.Zone;
|
||||||
|
import net.pietru.cookie_utils.api.Area;
|
||||||
|
import net.pietru.cookie_utils.api.Region;
|
||||||
|
import net.pietru.cookie_utils.permissions.ObjectPermList;
|
||||||
|
|
||||||
|
import static net.pietru.cookie_utils.utils.block_util.getBlockPositionFromGlobalXYZ;
|
||||||
|
|
||||||
|
public class areaFillSetup extends Setup {
|
||||||
|
BlockPosition p1;
|
||||||
|
BlockPosition p2;
|
||||||
|
|
||||||
|
String blockStateId;
|
||||||
|
|
||||||
|
public areaFillSetup() {
|
||||||
|
steps.add(()->{});
|
||||||
|
steps.add(()->{});
|
||||||
|
steps.add(this::run_setup_finish);
|
||||||
|
|
||||||
|
step_hints.add("Please select first position...");
|
||||||
|
step_hints.add("Please select second position...");
|
||||||
|
step_hints.add("Please enter region name (single word)...");
|
||||||
|
step_hints.add("Region creation complete");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
setupCreator.registerSetupCreator("region", areaFillSetup::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String get_setup_perm() {
|
||||||
|
return "setup.fill_area";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run_setup_finish() {
|
||||||
|
isActive=false;
|
||||||
|
if (!p1.getZone().equals(p2.getZone()))
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
Vector3 p1v=new Vector3(p1.getGlobalX(),p1.getGlobalY(),p1.getGlobalZ());
|
||||||
|
Vector3 p2v=new Vector3(p2.getGlobalX(),p2.getGlobalY(),p2.getGlobalZ());
|
||||||
|
|
||||||
|
Zone zone = p1.getZone();
|
||||||
|
Queue<BlockPosition> setQueue = new Queue<>();
|
||||||
|
int startX = (int) Math.min(p1v.x, p2v.x);
|
||||||
|
int endX = (int) Math.max(p1v.x, p2v.x);
|
||||||
|
int startY = (int) Math.min(p1v.y, p2v.y);
|
||||||
|
int endY = (int) Math.max(p1v.y, p2v.y);
|
||||||
|
int startZ = (int) Math.min(p1v.z, p2v.z);
|
||||||
|
int endZ = (int) Math.max(p1v.z, p2v.z);
|
||||||
|
|
||||||
|
for(int i = startX; i <= endX; ++i) {
|
||||||
|
for(int j = startY; j <= endY; ++j) {
|
||||||
|
for(int k = startZ; k <= endZ; ++k) {
|
||||||
|
BlockPosition pos = getBlockPositionFromGlobalXYZ(zone,i,j,k);
|
||||||
|
if (pos != null) {
|
||||||
|
setQueue.addLast(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (blockStateId != null) {
|
||||||
|
BlockState blockState;
|
||||||
|
|
||||||
|
blockState = BlockState.getInstance(blockStateId);
|
||||||
|
|
||||||
|
BlockSetter.get().replaceBlocks(zone, blockState, setQueue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run_setup_canceled() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean set_setup_text(String value) {
|
||||||
|
if (step==2)
|
||||||
|
blockStateId=value;
|
||||||
|
return step==2;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean set_setup_vector3(Vector3 value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean set_setup_block_pos(BlockPosition value) {
|
||||||
|
if (step==0)
|
||||||
|
p1=value;
|
||||||
|
else if (step==1)
|
||||||
|
p2=value;
|
||||||
|
return step==0 || step==1;
|
||||||
|
}
|
||||||
|
}
|
19
src/main/java/net/pietru/cookie_utils/utils/block_util.java
Normal file
19
src/main/java/net/pietru/cookie_utils/utils/block_util.java
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
package net.pietru.cookie_utils.utils;
|
||||||
|
|
||||||
|
import finalforeach.cosmicreach.blocks.BlockPosition;
|
||||||
|
import finalforeach.cosmicreach.world.Chunk;
|
||||||
|
import finalforeach.cosmicreach.world.Zone;
|
||||||
|
|
||||||
|
public class block_util {
|
||||||
|
public static BlockPosition getBlockPositionFromGlobalXYZ(Zone zone, int x, int y, int z) {
|
||||||
|
Chunk c = zone.getChunkAtBlock(x, y, z);
|
||||||
|
if (c == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
x -= 16 * Math.floorDiv(x, 16);
|
||||||
|
y -= 16 * Math.floorDiv(y, 16);
|
||||||
|
z -= 16 * Math.floorDiv(z, 16);
|
||||||
|
return new BlockPosition(c,x,y,z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue