use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.
the class SoundUtil method playSoundAtLocationExcept.
public static void playSoundAtLocationExcept(Location location, Sound sound, float volume, float pitch, GlowPlayer... exclude) {
if (location == null || sound == null)
return;
GlowWorld world = (GlowWorld) location.getWorld();
double radiusSquared = volume * volume * 256;
world.getRawPlayers().parallelStream().filter(player -> player.getLocation().distanceSquared(location) <= radiusSquared).filter(player -> !Arrays.asList(exclude).contains(player)).forEach(player -> player.playSound(location, sound, volume, pitch));
}
use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.
the class ProjectileDispenseBehavior method dispenseStack.
@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
GlowWorld world = block.getWorld();
Vector position = BlockDispenser.getDispensePosition(block);
BlockFace face = BlockDispenser.getFacing(block);
Projectile entity = getProjectileEntity(world, position);
entity.setVelocity(new Vector(face.getModX(), face.getModY() + 0.1f, face.getModZ()).multiply(6));
stack.setAmount(stack.getAmount() - 1);
if (stack.getAmount() < 1) {
return null;
}
return stack;
}
use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.
the class GlowLightningStrike method pulse.
@Override
public void pulse() {
super.pulse();
if (getTicksLived() >= ticksToLive) {
remove();
}
if (getTicksLived() == 1) {
GlowWorld world = (GlowWorld) location.getWorld();
// Play Sound
world.playSound(location, Sound.ENTITY_LIGHTNING_THUNDER, 10000, 0.8F + random.nextFloat() * 0.2F);
world.playSound(location, Sound.ENTITY_GENERIC_EXPLODE, 2, 0.5F + random.nextFloat() * 0.2F);
if (!effect) {
// set target block on fire if required
if (world.getGameRuleMap().getBoolean("doFireTick")) {
GlowBlock block = world.getBlockAt(location);
setBlockOnFire(block);
for (int i = 0; i < 4; i++) {
int x = location.getBlockX() - 1 + random.nextInt(3);
int z = location.getBlockZ() - 1 + random.nextInt(3);
int y = location.getBlockY() - 1 + random.nextInt(3);
block = world.getBlockAt(x, y, z);
setBlockOnFire(block);
}
}
// deal damage to nearby entities
for (Entity entity : getNearbyEntities(3, 6, 3)) {
if (entity instanceof Damageable) {
((Damageable) entity).damage(5, this, DamageCause.LIGHTNING);
}
entity.setFireTicks(entity.getMaxFireTicks());
}
}
}
}
use of net.glowstone.GlowWorld 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 net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.
the class DiggingHandler method handle.
@Override
public void handle(GlowSession session, DiggingMessage message) {
//Todo: Implement SHOOT_ARROW_FINISH_EATING
//Todo: Implement SWAP_ITEM_IN_HAND
GlowPlayer player = session.getPlayer();
GlowWorld world = player.getWorld();
GlowBlock block = world.getBlockAt(message.getX(), message.getY(), message.getZ());
BlockFace face = BlockPlacementHandler.convertFace(message.getFace());
ItemStack holding = player.getItemInHand();
if (block.getRelative(face).getType() == Material.FIRE) {
block.getRelative(face).breakNaturally();
// returns to avoid breaking block in creative
return;
}
boolean blockBroken = false;
boolean revert = false;
if (message.getState() == DiggingMessage.START_DIGGING) {
// call interact event
Action action = Action.LEFT_CLICK_BLOCK;
Block eventBlock = block;
if (player.getLocation().distanceSquared(block.getLocation()) > 36 || block.getTypeId() == 0) {
action = Action.LEFT_CLICK_AIR;
eventBlock = null;
}
PlayerInteractEvent interactEvent = EventFactory.onPlayerInteract(player, action, eventBlock, face);
// attempt to use item in hand, that is, dig up the block
if (!BlockPlacementHandler.selectResult(interactEvent.useItemInHand(), true)) {
// the event was cancelled, get out of here
revert = true;
} else if (player.getGameMode() != GameMode.SPECTATOR) {
player.setDigging(null);
// emit damage event - cancel by default if holding a sword
boolean instaBreak = player.getGameMode() == GameMode.CREATIVE || block.getMaterialValues().getHardness() == 0;
BlockDamageEvent damageEvent = new BlockDamageEvent(player, block, player.getItemInHand(), instaBreak);
if (player.getGameMode() == GameMode.CREATIVE && holding != null && EnchantmentTarget.WEAPON.includes(holding.getType())) {
damageEvent.setCancelled(true);
}
EventFactory.callEvent(damageEvent);
// follow orders
if (damageEvent.isCancelled()) {
revert = true;
} else {
// in creative, break even if denied in the event, or the block
// can never be broken (client does not send DONE_DIGGING).
blockBroken = damageEvent.getInstaBreak();
if (!blockBroken) {
/// TODO: add a delay here based on hardness
player.setDigging(block);
}
}
}
} else if (message.getState() == DiggingMessage.CANCEL_DIGGING) {
player.setDigging(null);
} else if (message.getState() == DiggingMessage.FINISH_DIGGING) {
// shouldn't happen in creative mode
// todo: verification against malicious clients
blockBroken = block.equals(player.getDigging());
if (blockBroken && holding.getType().getMaxDurability() != 0 && holding.getType() != Material.AIR && holding.getDurability() != holding.getType().getMaxDurability()) {
switch(block.getType()) {
case GRASS:
case DIRT:
case SAND:
case GRAVEL:
case MYCEL:
case SOUL_SAND:
switch(holding.getType()) {
case WOOD_SPADE:
case STONE_SPADE:
case IRON_SPADE:
case GOLD_SPADE:
case DIAMOND_SPADE:
holding.setDurability((short) (holding.getDurability() + 1));
break;
default:
holding.setDurability((short) (holding.getDurability() + 2));
break;
}
break;
case LOG:
case LOG_2:
case WOOD:
case CHEST:
switch(holding.getType()) {
case WOOD_AXE:
case STONE_AXE:
case IRON_AXE:
case GOLD_AXE:
case DIAMOND_AXE:
holding.setDurability((short) (holding.getDurability() + 1));
break;
default:
holding.setDurability((short) (holding.getDurability() + 2));
break;
}
break;
case STONE:
case COBBLESTONE:
switch(holding.getType()) {
case WOOD_PICKAXE:
case STONE_PICKAXE:
case IRON_PICKAXE:
case GOLD_PICKAXE:
case DIAMOND_PICKAXE:
holding.setDurability((short) (holding.getDurability() + 1));
break;
default:
holding.setDurability((short) (holding.getDurability() + 2));
break;
}
break;
default:
holding.setDurability((short) (holding.getDurability() + 2));
break;
}
if (holding.getType().getMaxDurability() != 0 && holding.getDurability() >= holding.getType().getMaxDurability()) {
player.getItemInHand().setType(Material.AIR);
}
}
player.setDigging(null);
} else if (message.getState() == DiggingMessage.STATE_DROP_ITEM) {
player.dropItemInHand(false);
return;
} else if (message.getState() == DiggingMessage.STATE_DROP_ITEMSTACK) {
player.dropItemInHand(true);
return;
} else if (message.getState() == DiggingMessage.STATE_SHOT_ARROW_FINISH_EATING && player.getUsageItem() != null) {
if (Objects.equals(player.getUsageItem(), holding)) {
ItemType type = ItemTable.instance().getItem(player.getUsageItem().getType());
if (type != null && type instanceof ItemTimedUsage) {
((ItemTimedUsage) type).endUse(player, player.getUsageItem());
} else {
// todo: inform the player that this item cannot be consumed/used
}
} else {
// todo: verification against malicious clients
// todo: inform player their item is wrong
}
return;
} else if (message.getState() == DiggingMessage.SWAP_ITEM_IN_HAND) {
ItemStack main = player.getInventory().getItemInMainHand();
ItemStack off = player.getInventory().getItemInOffHand();
player.getInventory().setItemInOffHand(main);
player.getInventory().setItemInMainHand(off);
player.updateInventory();
return;
} else {
return;
}
if (blockBroken && !revert) {
// fire the block break event
BlockBreakEvent breakEvent = EventFactory.callEvent(new BlockBreakEvent(block, player));
if (breakEvent.isCancelled()) {
BlockPlacementHandler.revert(player, block);
return;
}
MaterialData data = block.getState().getData();
if (data instanceof DoublePlant) {
if (((DoublePlant) data).getSpecies() == DoublePlantSpecies.PLANT_APEX && block.getRelative(BlockFace.DOWN).getState().getData() instanceof DoublePlant) {
block = block.getRelative(BlockFace.DOWN);
}
}
BlockType blockType = ItemTable.instance().getBlock(block.getType());
if (blockType != null) {
blockType.blockDestroy(player, block, face);
}
// destroy the block
if (!block.isEmpty() && !block.isLiquid() && (player.getGameMode() != GameMode.CREATIVE || blockType instanceof BlockContainer) && world.getGameRuleMap().getBoolean("doTileDrops")) {
Collection<ItemStack> drops = blockType.getDrops(block, holding);
if (blockType instanceof BlockContainer && player.getGameMode() == GameMode.CREATIVE) {
drops = ((BlockContainer) blockType).getContentDrops(block);
}
for (ItemStack drop : drops) {
GlowItem item = world.dropItemNaturally(block.getLocation(), drop);
item.setPickupDelay(30);
item.setBias(player);
}
}
player.addExhaustion(0.005f);
// STEP_SOUND actually is the block break particles
world.playEffectExceptTo(block.getLocation(), Effect.STEP_SOUND, block.getTypeId(), 64, player);
GlowBlockState state = block.getState();
block.setType(Material.AIR);
if (blockType != null) {
blockType.afterDestroy(player, block, face, state);
}
} else if (revert) {
// replace the block that wasn't really dug
BlockPlacementHandler.revert(player, block);
} else if (block.getType() != Material.AIR) {
BlockType blockType = ItemTable.instance().getBlock(block.getType());
blockType.leftClickBlock(player, block, holding);
}
}
Aggregations