@Override public String toString() { return (isHeadOfBed() ? "HEAD" : "FOOT") + " of " + super.toString() + " facing " + getFacing(); }
/** * Instantiate a bed facing in a particular direction. * * @param direction the direction the bed's head is facing */ public Bed(BlockFace direction) { this(); setFacingDirection(direction); }
/** * Set which direction the head of the bed is facing. Note that this will * only affect one of the two blocks the bed is made of. */ public void setFacingDirection(BlockFace face) { byte data; switch (face) { case SOUTH: data = 0x0; break; case WEST: data = 0x1; break; case NORTH: data = 0x2; break; case EAST: default: data = 0x3; } if (isHeadOfBed()) { data |= 0x8; } setData(data); }
private void dropTargetBlock(Block targetBlock) { if (targetBlock.getType().equals(Material.BED_BLOCK)) { Block bedHead; Block bedFeet; Bed bedBlock = (Bed) targetBlock.getState().getData(); if (!bedBlock.isHeadOfBed()) { bedFeet = targetBlock; bedHead = Utils.getBedNeighbor(bedFeet); } else { bedHead = targetBlock; bedFeet = Utils.getBedNeighbor(bedHead); } if (!BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_12")) { bedFeet.setType(Material.AIR); } else { bedHead.setType(Material.AIR); } } else { targetBlock.setType(Material.AIR); } }
@Override public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) { if (block.getType() == Material.BED_BLOCK) { GlowBed bed = (GlowBed) block.getState(); bed.setColor(DyeColor.getByWoolData(holding.getData().getData())); bed.update(true); BlockFace direction = ((Bed) bed.getData()).getFacing(); GlowBlock headBlock = block.getRelative(direction); headBlock.setType(Material.BED_BLOCK); GlowBed headBlockState = (GlowBed) headBlock.getState(); headBlockState.setColor(DyeColor.getByWoolData(holding.getData().getData())); MaterialData data = headBlockState.getData(); ((Bed) data).setHeadOfBed(true); ((Bed) data).setFacingDirection(direction); headBlockState.setData(data); headBlockState.update(true); } }
@Override public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) { BlockFace direction = getOppositeBlockFace(player.getLocation(), false).getOppositeFace(); super.placeBlock(player, state, face, holding, clickedLoc); MaterialData data = state.getData(); if (data instanceof Bed) { ((Bed) data).setFacingDirection(direction); ((Bed) data).setHeadOfBed(false); state.setData(data); } else { warnMaterialData(Bed.class, data); } }
public RepairableBed(BlockState state) { super(state); other = state.getBlock().getRelative(((Bed) state.getData()).getFacing()).getState(); }
/** * Determine if this block represents the head of the bed * * @return true if this is the head of the bed, false if it is the foot */ public boolean isHeadOfBed() { return (getData() & 0x8) == 0x8; }
private void dropTargetBlock(Block targetBlock) { if (targetBlock.getType().equals(Material.BED_BLOCK)) { Block bedHead; Block bedFeet; Bed bedBlock = (Bed) targetBlock.getState().getData(); if (!bedBlock.isHeadOfBed()) { bedFeet = targetBlock; bedHead = Utils.getBedNeighbor(bedFeet); } else { bedHead = targetBlock; bedFeet = Utils.getBedNeighbor(bedHead); } if (!BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_12")) { bedFeet.setType(Material.AIR); } else { bedHead.setType(Material.AIR); } } else { targetBlock.setType(Material.AIR); } }
/** * Set which direction the head of the bed is facing. Note that this will * only affect one of the two blocks the bed is made of. */ public void setFacingDirection(BlockFace face) { byte data; switch (face) { case SOUTH: data = 0x0; break; case WEST: data = 0x1; break; case NORTH: data = 0x2; break; case EAST: default: data = 0x3; } if (isHeadOfBed()) { data |= 0x8; } setData(data); }
bedHead.setHeadOfBed(true); bedHead.setFacingDirection(blockHead.getFace(blockFeed).getOppositeFace()); bedFeed.setHeadOfBed(false); bedFeed.setFacingDirection(blockFeed.getFace(blockHead));
/** * Get the direction that this bed's head is facing toward * * @return the direction the head of the bed is facing */ public BlockFace getFacing() { byte data = (byte) (getData() & 0x7); switch (data) { case 0x0: return BlockFace.SOUTH; case 0x1: return BlockFace.WEST; case 0x2: return BlockFace.NORTH; case 0x3: default: return BlockFace.EAST; } }
/** * Returns the head of a bed given one of its blocks. * * @param block part of the bed * @return The head of the bed */ public static GlowBlock getHead(GlowBlock block) { MaterialData data = block.getState().getData(); if (!(data instanceof Bed)) { return null; } Bed bed = (Bed) data; if (bed.isHeadOfBed()) { return block; } else { return block.getRelative(bed.getFacing()); } }
Bed theBed = (Bed) theBlock.getState().getData(); if (!theBed.isHeadOfBed()) { neighbor = theBlock; theBlock = Utils.getBedNeighbor(neighbor);
bedHead.setHeadOfBed(true); bedHead.setFacingDirection(blockHead.getFace(blockFeed).getOppositeFace()); bedFeed.setHeadOfBed(false); bedFeed.setFacingDirection(blockFeed.getFace(blockHead));
/** * Instantiate a bed facing in a particular direction. * * @param direction the direction the bed's head is facing */ public Bed(BlockFace direction) { this(); setFacingDirection(direction); }
/** * Determine if this block represents the head of the bed * * @return true if this is the head of the bed, false if it is the foot */ public boolean isHeadOfBed() { return (getData() & 0x8) == 0x8; }
/** * Returns the foot of a bed given one of its blocks. * * @param block part of the bed * @return The foot of the bed */ public static GlowBlock getFoot(GlowBlock block) { MaterialData data = block.getState().getData(); if (!(data instanceof Bed)) { return null; } Bed bed = (Bed) data; if (bed.isHeadOfBed()) { return block.getRelative(bed.getFacing().getOppositeFace()); } else { return block; } }