private static BlockFace getFaceToRightDoor(Block bottomHalfDoorBlock) { Door door = asDoorMaterialOrNull(bottomHalfDoorBlock); if (door == null) { throw new RuntimeException("Block " + bottomHalfDoorBlock + " is not a door"); } switch (door.getFacing()) { case WEST: return BlockFace.SOUTH; case NORTH: return BlockFace.WEST; case EAST: return BlockFace.NORTH; case SOUTH: return BlockFace.EAST; default: throw new RuntimeException("Invalid facing for door: " + door); } }
/** * Opens or closes the door. If the door has been destroyed after creating * * @param open * Whether the door must be opened (true) or closed (false). * @param soundAction * Whether a sound must be played. */ public void setOpen(boolean open, SoundCondition soundAction) { Door leftDoor = asDoorMaterialOrNull(bottomLeftBlock); if (leftDoor != null) { // Sound effect playSound(bottomLeftBlock, open, soundAction); // Don't play sound for other half soundAction = SoundCondition.NEVER; // Door toggle leftDoor.setOpen(open); BlockData.set(bottomLeftBlock, leftDoor); } Door rightDoor = asDoorMaterialOrNull(bottomRightBlock); if (rightDoor != null) { // Sound effect playSound(bottomRightBlock, open, soundAction); // Door toggle rightDoor.setOpen(open); BlockData.set(bottomRightBlock, rightDoor); } }
@Override public Text translateAction(User user) { // TODO plurals @SuppressWarnings("deprecation") boolean open = this.newBlock.as(Door.class).isOpen(); if (open) { return user.getTranslation(POSITIVE, "{user} opened the {name#block}", this.player.name, this.oldBlock.name()); } else { return user.getTranslation(POSITIVE, "{user} closed the {name#block}", this.player.name, this.oldBlock.name()); } }
@Override public void checkMove(MoveData inData) { if(inData.isValid()) return; if(inData.getAboveBlock().getType() == Material.FENCE_GATE) { Gate g = (Gate)inData.getAboveBlock().getState().getData(); if(g.isOpen()) inData.setValid(true); } else if(inData.getAboveBlock().getType() == Material.WOOD_DOOR || (!this.m_ironDoor && inData.getAboveBlock().getType() == Material.IRON_DOOR_BLOCK)) { Door d = (Door)inData.getAboveBlock().getState().getData(); if(d.isOpen()) inData.setValid(true); } }
/** * checks if this block would give a reaction if you click on it without * shifting, e.g. opening a chest or switching a lever */ public static boolean isInteractiveBlock(Block b) { if (b == null || b.getState() == null) { return false; } if (b.getType() == Material.WORKBENCH || b.getType() == Material.ENCHANTMENT_TABLE || b.getType() == Material.ANVIL || b.getType() == Material.BREWING_STAND || b.getState() instanceof InventoryHolder || b.getState() instanceof NoteBlock) { return true; } if (b.getState().getData() instanceof Button || b.getState().getData() instanceof Lever || b.getState().getData() instanceof Door || b.getState().getData() instanceof TrapDoor || b.getState().getData() instanceof Gate || b.getState().getData() instanceof Comparator) { if (b.getType() != Material.IRON_DOOR && b.getType() != Material.IRON_DOOR_BLOCK && b.getType() != Material.IRON_TRAPDOOR) { return true; } } return false; }
private static Door asDoorMaterialOrNull(Block nullableBlock) { if (nullableBlock == null) { return null; } MaterialData materialData = BlockData.get(nullableBlock); if (materialData instanceof Door) { return (Door) materialData; } return null; }
private static Hinge getHinge(Block topHalfDoorBlock) { Door door = asDoorMaterialOrNull(topHalfDoorBlock); if (door != null) { return door.getHinge() == false ? Hinge.LEFT : Hinge.RIGHT; } return Hinge.UNKNOWN; }
private static boolean isTopHalf(Block doorBlock) { Door door = asDoorMaterialOrNull(doorBlock); if (door != null) { return door.isTopHalf(); } return false; }
/** * Gets whether the door is currently open. The result is undefined if the * door is half-open, half-closed. * * @return True if the door is currently open, false otherwise. */ public boolean isOpen() { MaterialData materialData = null; if (bottomRightBlock != null) { materialData = BlockData.get(bottomRightBlock); } if (bottomLeftBlock != null) { materialData = BlockData.get(bottomLeftBlock); } return (materialData instanceof Door) && ((Door) materialData).isOpen(); }
public Door() { }
@Deprecated public Door(int type) { }
public Door(Material type) { }
@Deprecated public Door(int type, byte data) { }
@Deprecated public Door(Material type, byte data) { }
public Door clone() { return null; }