我有一个名为“区域”的类,它创建区域并检查坐标是否在其中。然后我有其他类'ArrowTower'扩展'Region'。'ArrowTower' 类创建塔。我整天都在试验,没有结果。我想要做的是将第一个和第二个位置分配给“区域”类,然后创建区域并检查坐标是否属于它。我也有事件 - 'BlockTouch' 类创建 'ArrowTower' 对象。当我尝试它时,tower.insideRegion(e.getClickedBlock());
它给了我我的位置然后归零,因为它没有在 中设置值public void buildArrowTower
,但值就在这里。所以我只是不明白为什么这不起作用:/
我的活动课程:
import eu.anavicius.TomTom1997.TomTowerDefence.Towers.ArrowTower;
public class BlockTouch implements Listener {
@EventHandler
public void onPlayerInteract(PlayerInteractEvent e) {
ArrowTower tower = new ArrowTower();
if (e.getAction() == Action.RIGHT_CLICK_BLOCK ) {
if (e.getItem().getType() == Material.ARROW) {
tower.buildArrowTower(e.getClickedBlock(),e.getPlayer());
} else if (e.getItem().getType() == Material.BONE) {
Bukkit.broadcastMessage("Bone");
tower.insideRegion(e.getClickedBlock());
}
}
}
}
我的 Region.class:
public class Regions {
private int xl,yl,zl,xh,yh,zh;
public void setLRegion (int x, int y, int z) {
xl = x;
yl = y;
zl = z;
//Bukkit.broadcastMessage("SetLMethod" + " \t " + "|" + xl + "|"+ xh + "||" + "|" + yl + "|" + yh + "||" + "|" +zl + "|" + zh + "||");
}
public void setHRegion (int x, int y, int z) {
xh = x;
yh = y;
zh = z;
//Bukkit.broadcastMessage("SetHMethod" + " \t " + "|" + xl + "|"+ xh + "||" + "|" + yl + "|" + yh + "||" + "|" +zl + "|" + zh + "||");
}
public void insideRegion (Block l) {
int x,y,z;
x = l.getX();
y = l.getY();
z =l.getZ();
Bukkit.broadcastMessage("InsideMethod" + " \\t " + x + "|" + xl + "|"+ xh + "||" +y + "|" + yl + "|" + yh + "||" + z + "|" +zl + "|" + zh + "||");
if (x >= xl && x <= xh ) {
Bukkit.broadcastMessage("Region check 1");
if (z >= zl && z <= zh) {
Bukkit.broadcastMessage("Region check 2");
if (y >= yl && y >= yh) {
Bukkit.broadcastMessage("Regione");
}
}
}
}
}
我的 ArrowTower.class:
public class ArrowTower extends Regions {
public ArrowTower () {
}
public void buildArrowTower (Block b,Player p) {
if (b.getType().equals(Material.EMERALD_BLOCK)) {
Location loc = b.getLocation();
for (int y = 0; y < 4;y++) {
int layloc = 0;
int by = loc.getBlock().getY()+1 + y;
for (int x = 0;x <3;x++) {
int bx = loc.getBlock().getX()-1 + x;
for (int z = 0;z < 3;z++) { // Pagalvot dar del delay, nes su kintamaisiais pirma blogai buvau
int bz = loc.getBlock().getZ()-1 + z; // sugalvojas, atsispausdina tuscios vietos
Location block = new Location(b.getWorld(),bx,by,bz); // pass loop values to method
if (y == 0 && layloc == 0) {
Bukkit.broadcastMessage("SetR L");
setLRegion(bx,by,bz);
} else if (y == 3 && layloc == 8) {
Bukkit.broadcastMessage("SetR H");
setHRegion(bx,by,bz);
}
block.getBlock().setType(Material.matchMaterial(towerl1(y,layloc)));
layloc++;
}
}
}
}
}
public String towerl1(int h, int layloc) {
String[] layer1 = { // - l
"LOG","AIR","LOG",
"AIR","AIR","AIR",
"LOG","AIR","LOG"};
String[] layer2 = { // - i
"COBBLE_WALL","COBBLESTONE","COBBLE_WALL",
"COBBLESTONE","AIR","COBBLESTONE",
"COBBLE_WALL","COBBLESTONE","COBBLE_WALL"};
String[] layer3 = { // - t
"COBBLE_WALL","AIR","COBBLE_WALL",
"COBBLE_WALL","MOSSY_COBBLESTONE","COBBLE_WALL",
"COBBLE_WALL","AIR","COBBLE_WALL"};
String[] layer4 = {
"AIR","AIR","AIR",
"AIR","JACK_O_LANTERN","AIR",
"AIR","AIR","AIR"};
if (h == 0) {
return layer1[layloc];
} else if (h == 1) {
return layer2[layloc];
} else if (h == 2) {
return layer3[layloc];
} else if (h == 3) {
return layer4[layloc];
} else {
return null;
}
}
}