/** * Clarity method for getting the placed block. Not really needed except * for reasons of clarity. * * @return The Block that was placed */ public Block getBlockPlaced() { return getBlock(); }
/** * Gets the location where the possible moving block might be if the * retracting piston is sticky. * * @return The possible location of the possibly moving block. */ public Location getRetractLocation() { return getBlock().getRelative(getDirection(), 2).getLocation(); }
private boolean setCauldronLevel(GlowBlock block, int newLevel, Entity entity, CauldronLevelChangeEvent.ChangeReason reason) { int oldLevel = (int) block.getData(); CauldronLevelChangeEvent event = EventFactory.getInstance().callEvent( new CauldronLevelChangeEvent(block, entity, reason, oldLevel, newLevel)); if (!event.isCancelled()) { block.setData((byte) event.getNewLevel()); } return !event.isCancelled(); }
private void flow(GlowBlock source, BlockFace direction) { // if we're not going down BlockFromToEvent fromToEvent = new BlockFromToEvent(source, direction); if (fromToEvent.isCancelled()) { return; } byte strength = fromToEvent.getBlock().getState().getRawData(); if (DOWN != fromToEvent.getFace()) { if (strength < (isWater(fromToEvent.getBlock().getType()) || fromToEvent.getBlock().getBiome() == Biome.HELL ? STRENGTH_MIN_WATER : STRENGTH_MIN_LAVA)) { // decrease the strength strength += 1; } else { // no strength, can't flow return; } } else { // reset the strength if we're going down strength = STRENGTH_MAX; } // flow to the target GlowBlock toBlock = (GlowBlock) fromToEvent.getToBlock(); toBlock.setType(fromToEvent.getBlock().getType(), strength, false); toBlock.getWorld().requestPulse(toBlock); }
/** * Get an immutable list of the blocks which will be moved by the * extending. * * @return Immutable list of the moved blocks. */ public List<Block> getBlocks() { if (blocks == null) { ArrayList<Block> tmp = new ArrayList<Block>(); for (int i = 0; i < this.getLength(); i++) { tmp.add(block.getRelative(getDirection(), i + 1)); } blocks = Collections.unmodifiableList(tmp); } return blocks; }
BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state); EventFactory.getInstance().callEvent(fadeEvent); if (!fadeEvent.isCancelled()) { state.update(true); state.setType(Material.MYCEL); state.setRawData((byte) 0); BlockSpreadEvent spreadEvent = new BlockSpreadEvent(targetBlock, block, state); EventFactory.getInstance().callEvent(spreadEvent); if (!spreadEvent.isCancelled()) { state.update(true);
@Override public void updateBlock(GlowBlock block) { GlowBlockState state = block.getState(); state.setType(Material.REDSTONE_ORE); BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state); EventFactory.getInstance().callEvent(fadeEvent); if (!fadeEvent.isCancelled()) { state.update(true); } } }
private void setBlockOnFire(GlowBlock block) { if (ThreadLocalRandom.current().nextInt(3) != 0) { return; } Block below = block.getRelative(BlockFace.DOWN); Material belowType = below.getType(); if (belowType == Material.AIR || belowType == Material.FIRE || !belowType.isFlammable()) { return; } BlockIgniteEvent event = EventFactory.getInstance().callEvent( new BlockIgniteEvent(block, IgniteCause.EXPLOSION, source)); if (event.isCancelled()) { return; } block.setType(Material.FIRE); }
@Override public void updateBlock(GlowBlock block) { int cropState = block.getData(); if (cropState < NetherWartsState.RIPE.ordinal() && ThreadLocalRandom.current().nextInt(10) == 0) { cropState++; GlowBlockState state = block.getState(); state.setRawData((byte) cropState); BlockGrowEvent growEvent = new BlockGrowEvent(block, state); EventFactory.getInstance().callEvent(growEvent); if (!growEvent.isCancelled()) { state.update(true); } } } }
/** * <p>Called when the BlockType should calculate the current physics.</p> * <p>Subclasses should override {@link #updatePhysicsAfterEvent(GlowBlock)} * if they need a custom handling of the physics calculation</p> * * @param block The block */ public final void updatePhysics(GlowBlock block) { if (!block.getWorld().isInitialized()) { return; } BlockPhysicsEvent event = EventFactory.getInstance() .callEvent(new BlockPhysicsEvent(block, block.getTypeId())); if (!event.isCancelled()) { updatePhysicsAfterEvent(block); } }
private void putVine(GlowBlock block, Vine vine, GlowBlock fromBlock) { GlowBlockState state = block.getState(); state.setType(Material.VINE); state.setData(vine); if (fromBlock != null) { BlockSpreadEvent spreadEvent = new BlockSpreadEvent(block, fromBlock, state); EventFactory.getInstance().callEvent(spreadEvent); if (!spreadEvent.isCancelled()) { state.update(true); } } else { state.update(true); } }
BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state); EventFactory.getInstance().callEvent(fadeEvent); if (!fadeEvent.isCancelled()) { state.update(true); state.setType(Material.GRASS); state.setRawData((byte) 0); BlockSpreadEvent spreadEvent = new BlockSpreadEvent(targetBlock, block, state); EventFactory.getInstance().callEvent(spreadEvent); if (!spreadEvent.isCancelled()) { state.update(true);
@Override public void updateBlock(GlowBlock block) { if (block.getLightFromBlocks() > 11) { GlowBlockState state = block.getState(); state.setType(Material.AIR); state.setData(new MaterialData(Material.AIR)); BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state); EventFactory.getInstance().callEvent(fadeEvent); if (!fadeEvent.isCancelled()) { state.update(true); } } } }
private void setBlockOnFire(GlowBlock block) { if (block.isEmpty() && block.getRelative(BlockFace.DOWN).isFlammable()) { BlockIgniteEvent igniteEvent = new BlockIgniteEvent(block, IgniteCause.LIGHTNING, this); EventFactory.getInstance().callEvent(igniteEvent); if (!igniteEvent.isCancelled()) { BlockState state = block.getState(); state.setType(Material.FIRE); state.update(true); } } }
@Override public void grow(GlowPlayer player, GlowBlock block) { GlowBlockState state = block.getState(); int cropState = block.getData() + ThreadLocalRandom.current().nextInt(CropState.MEDIUM.ordinal()) + CropState.VERY_SMALL.ordinal(); if (cropState > CropState.RIPE.ordinal()) { cropState = CropState.RIPE.ordinal(); } state.setRawData((byte) cropState); BlockGrowEvent growEvent = new BlockGrowEvent(block, state); EventFactory.getInstance().callEvent(growEvent); if (!growEvent.isCancelled()) { state.update(true); } }
@Override public void updateBlock(GlowBlock block) { if (block.getLightFromBlocks() > 11) { GlowBlockState state = block.getState(); state.setType(Material.AIR); state.setData(new MaterialData(Material.AIR)); BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state); EventFactory.getInstance().callEvent(fadeEvent); if (!fadeEvent.isCancelled()) { state.update(true); } } } }
private boolean setBlockOnFire(GlowPlayer player, GlowBlock clicked, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) { GlowBlock fireBlock = clicked.getRelative(face); if (fireBlock.getType() != Material.AIR) { return true; } if (!clicked.isFlammable() && clicked.getRelative(BlockFace.DOWN).getType() == Material.AIR) { return true; } BlockIgniteEvent event = EventFactory.getInstance() .callEvent(new BlockIgniteEvent(fireBlock, IgniteCause.FLINT_AND_STEEL, player, null)); if (event.isCancelled()) { player.setItemInHand(holding); return false; } // clone holding to avoid decreasing of the item's amount ItemTable.instance().getBlock(Material.FIRE) .rightClickBlock(player, clicked, face, holding.clone(), clickedLoc, hand); return true; } }
@Override public void grow(GlowPlayer player, GlowBlock block) { GlowBlockState state = block.getState(); int cropState = block.getData() + ThreadLocalRandom.current().nextInt(CropState.MEDIUM.ordinal()) + CropState.VERY_SMALL.ordinal(); if (cropState > CropState.RIPE.ordinal()) { cropState = CropState.RIPE.ordinal(); } state.setRawData((byte) cropState); BlockGrowEvent growEvent = new BlockGrowEvent(block, state); EventFactory.getInstance().callEvent(growEvent); if (!growEvent.isCancelled()) { state.update(true); } }
@Override public void updateBlock(GlowBlock block) { if (block.getLightFromBlocks() > 11 - block.getMaterialValues().getLightOpacity()) { Material type = block.getWorld().getEnvironment() == Environment.NETHER ? Material.AIR : Material.STATIONARY_WATER; GlowBlockState state = block.getState(); state.setType(type); state.setData(new MaterialData(type)); BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state); EventFactory.getInstance().callEvent(fadeEvent); if (!fadeEvent.isCancelled()) { state.update(true); } } } }
@Override public void grow(GlowPlayer player, GlowBlock block) { MaterialData data = block.getState().getData(); if (data instanceof CocoaPlant) { CocoaPlant cocoa = (CocoaPlant) data; CocoaPlantSize size = cocoa.getSize(); if (size == CocoaPlantSize.SMALL) { cocoa.setSize(CocoaPlantSize.MEDIUM); } else if (size == CocoaPlantSize.MEDIUM) { cocoa.setSize(CocoaPlantSize.LARGE); } else { return; } GlowBlockState state = block.getState(); state.setData(cocoa); BlockGrowEvent growEvent = new BlockGrowEvent(block, state); EventFactory.getInstance().callEvent(growEvent); if (!growEvent.isCancelled()) { state.update(true); } } else { warnMaterialData(CocoaPlant.class, data); } }