use of org.bukkit.material.Door in project Citizens2 by CitizensDev.
the class AStarNavigationStrategy method update.
@Override
public boolean update() {
if (!planned) {
Location location = npc.getEntity().getLocation();
VectorGoal goal = new VectorGoal(destination, (float) params.pathDistanceMargin());
setPlan(ASTAR.runFully(goal, new VectorNode(goal, location, new ChunkBlockSource(location, params.range()), params.examiners()), Setting.MAXIMUM_ASTAR_ITERATIONS.asInt()));
}
if (getCancelReason() != null || plan == null || plan.isComplete()) {
return true;
}
Location currLoc = npc.getEntity().getLocation(NPC_LOCATION);
if (currLoc.toVector().distanceSquared(vector) <= params.distanceMargin()) {
plan.update(npc);
if (plan.isComplete()) {
return true;
}
vector = plan.getCurrentVector();
}
double dX = vector.getBlockX() - currLoc.getX();
double dZ = vector.getBlockZ() - currLoc.getZ();
double dY = vector.getY() - currLoc.getY();
double xzDistance = dX * dX + dZ * dZ;
double distance = xzDistance + dY * dY;
if (params.debug()) {
npc.getEntity().getWorld().playEffect(vector.toLocation(npc.getEntity().getWorld()), Effect.ENDER_SIGNAL, 0);
}
if (distance > 0 && dY > NMS.getStepHeight(npc.getEntity()) && xzDistance <= 2.75) {
NMS.setShouldJump(npc.getEntity());
}
double destX = vector.getX() + 0.5, destZ = vector.getZ() + 0.5;
Block block = currLoc.getWorld().getBlockAt(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ());
if (MinecraftBlockExaminer.isDoor(block.getType())) {
Door door = (Door) block.getState().getData();
if (door.isOpen()) {
BlockFace targetFace = door.getFacing().getOppositeFace();
destX = vector.getX() + targetFace.getModX();
destZ = vector.getZ() + targetFace.getModZ();
}
}
NMS.setDestination(npc.getEntity(), destX, vector.getY(), destZ, params.speed());
params.run();
plan.run(npc);
return false;
}
use of org.bukkit.material.Door in project Towny by ElgarL.
the class ProtectionRegenTask method replaceProtections.
public void replaceProtections() {
try {
Block block = state.getBlock();
if (state.getData() instanceof Door) {
Door door = (Door) state.getData();
Block topHalf;
Block bottomHalf;
if (door.isTopHalf()) {
topHalf = block;
bottomHalf = block.getRelative(BlockFace.DOWN);
} else {
bottomHalf = block;
topHalf = block.getRelative(BlockFace.UP);
}
door.setTopHalf(true);
topHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
door.setTopHalf(false);
bottomHalf.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
} else if (state instanceof Sign) {
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
Sign sign = (Sign) block.getState();
int i = 0;
for (String line : ((Sign) state).getLines()) sign.setLine(i++, line);
sign.update(true);
} else if (state instanceof CreatureSpawner) {
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
((CreatureSpawner) block.getState()).setSpawnedType(((CreatureSpawner) state).getSpawnedType());
} else if (state instanceof InventoryHolder) {
block.setTypeId(state.getTypeId(), false);
// Container to receive the inventory
Inventory container = ((InventoryHolder) block.getState()).getInventory();
container.setContents(contents.toArray(new ItemStack[0]));
block.setData(state.getData().getData(), false);
} else if (state.getData() instanceof PistonExtensionMaterial) {
PistonExtensionMaterial extension = (PistonExtensionMaterial) state.getData();
Block piston = block.getRelative(extension.getAttachedFace());
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
if (altState != null) {
piston.setTypeIdAndData(altState.getTypeId(), altState.getData().getData(), false);
}
} else if (state.getData() instanceof Attachable) {
Block attachedBlock = block.getRelative(((Attachable) state.getData()).getAttachedFace());
if (attachedBlock.getTypeId() == 0) {
attachedBlock.setTypeId(placeholder.getId(), false);
TownyRegenAPI.addPlaceholder(attachedBlock);
}
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), false);
} else {
if (NeedsPlaceholder.contains(state.getType())) {
Block blockBelow = block.getRelative(BlockFace.DOWN);
if (blockBelow.getTypeId() == 0) {
if (state.getType().equals(Material.CROPS)) {
blockBelow.setTypeId(Material.SOIL.getId(), true);
} else {
blockBelow.setTypeId(placeholder.getId(), true);
}
TownyRegenAPI.addPlaceholder(blockBelow);
}
}
block.setTypeIdAndData(state.getTypeId(), state.getData().getData(), !NeedsPlaceholder.contains(state.getType()));
}
TownyRegenAPI.removePlaceholder(block);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.bukkit.material.Door in project Glowstone by GlowstoneMC.
the class BlockDoor method blockInteract.
/**
* Opens and closes the door when right-clicked by the player.
*/
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
// handles opening and closing the door
if (block.getType() == Material.IRON_DOOR) {
return false;
}
GlowBlockState state = block.getState();
MaterialData data = state.getData();
if (data instanceof Door) {
Door door = (Door) data;
if (door.isTopHalf()) {
door = null;
block = block.getWorld().getBlockAt(block.getX(), block.getY() - 1, block.getZ());
state = block.getState();
data = state.getData();
if (data instanceof Door) {
door = (Door) data;
}
}
if (door != null) {
door.setOpen(!door.isOpen());
}
state.update(true);
}
return true;
}
use of org.bukkit.material.Door in project Glowstone by GlowstoneMC.
the class BlockDoor method onBlockChanged.
@Override
public void onBlockChanged(GlowBlock block, Material oldType, byte oldData, Material newType, byte newData) {
if (newType != Material.AIR) {
return;
}
if (oldType.getData() == Door.class) {
Door door = new Door(oldType);
door.setData(oldData);
if (door.isTopHalf()) {
Block b = block.getRelative(BlockFace.DOWN);
if (b.getState().getData() instanceof Door) {
b.setType(Material.AIR);
}
} else {
Block b = block.getRelative(BlockFace.UP);
if (b.getState().getData() instanceof Door) {
b.setType(Material.AIR);
}
}
}
}
use of org.bukkit.material.Door in project Glowstone by GlowstoneMC.
the class BlockDoor method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
// place the door and calculate the facing
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (!(data instanceof Door)) {
warnMaterialData(Door.class, data);
return;
}
BlockFace facing = player.getCardinalFacing();
((Door) data).setFacingDirection(facing.getOppositeFace());
// modify facing for double-doors
GlowBlock leftBlock = null;
byte newDirectionData = 0;
switch(facing) {
case NORTH:
leftBlock = state.getBlock().getRelative(BlockFace.WEST);
newDirectionData = 6;
break;
case WEST:
leftBlock = state.getBlock().getRelative(BlockFace.SOUTH);
newDirectionData = 5;
break;
case SOUTH:
leftBlock = state.getBlock().getRelative(BlockFace.EAST);
newDirectionData = 4;
break;
case EAST:
leftBlock = state.getBlock().getRelative(BlockFace.NORTH);
newDirectionData = 7;
break;
default:
}
if (leftBlock != null && leftBlock.getState().getData() instanceof Door) {
data.setData(newDirectionData);
}
// place top half of door
GlowBlockState topState = state.getBlock().getRelative(BlockFace.UP).getState();
topState.setType(state.getType());
MaterialData topData = topState.getData();
if (!(topData instanceof Door)) {
warnMaterialData(Door.class, data);
} else {
((Door) topData).setTopHalf(true);
topState.update(true);
}
}
Aggregations