use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockBed method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
BlockFace direction = getOppositeBlockFace(player.getLocation(), false).getOppositeFace();
if (state.getBlock().getRelative(direction).getType() == Material.AIR && state.getBlock().getRelative(direction).getRelative(BlockFace.DOWN).getType().isSolid()) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (data instanceof Bed) {
((Bed) data).setFacingDirection(direction);
state.setData(data);
} else {
warnMaterialData(Bed.class, data);
}
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockBed method blockInteract.
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
GlowWorld world = player.getWorld();
MaterialData data = block.getState().getData();
if (!(data instanceof Bed)) {
warnMaterialData(Bed.class, data);
return false;
}
block = getHead(block);
// Disallow sleeping in nether and end biomes
Biome biome = block.getBiome();
if (biome == Biome.HELL || biome == Biome.SKY) {
// Set off an explosion at the bed slightly stronger than TNT
world.createExplosion(block.getLocation(), 5F, true);
return true;
}
// Tick values for day/night time taken from the minecraft wiki
if (world.getTime() < 12541 || world.getTime() > 23458 || world.isThundering()) {
player.sendMessage("You can only sleep at night");
return true;
}
if (isOccupied(block)) {
player.sendMessage("This bed is occupied.");
return true;
}
if (!isWithinDistance(player, block, 3, 2, 3)) {
// Distance between player and bed is too great, fail silently
return true;
}
for (LivingEntity e : world.getLivingEntities()) {
// Check for hostile mobs relative to the block below the head of the bed
if (e instanceof Creature && isWithinDistance(e, block.getRelative(BlockFace.DOWN), 8, 5, 8)) {
player.sendMessage("You may not rest now, there are monsters nearby");
return true;
}
}
player.enterBed(block);
return true;
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockDispenser method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (data instanceof Dispenser) {
((Dispenser) data).setFacingDirection(getOppositeBlockFace(player.getLocation(), true));
state.setData(data);
} else {
warnMaterialData(Dispenser.class, data);
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockButton method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (!(data instanceof Button)) {
warnMaterialData(Button.class, data);
return;
}
setAttachedFace(state, face.getOppositeFace());
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockCocoa method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
MaterialData data = block.getState().getData();
if (data instanceof CocoaPlant) {
CocoaPlant cocoa = (CocoaPlant) data;
CocoaPlantSize size = cocoa.getSize();
if (size != CocoaPlantSize.LARGE && random.nextInt(5) == 0) {
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.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
}
} else {
warnMaterialData(CocoaPlant.class, data);
}
}
Aggregations