use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class FlintAndSteelDispenseBehavior method dispenseStack.
@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
GlowBlock target = block.getRelative(BlockDispenser.getFacing(block));
successful = true;
if (target.getType() == Material.AIR) {
target.setType(Material.FIRE);
stack.setDurability((short) (stack.getDurability() + 1));
ItemType type = ItemTable.instance().getItem(stack.getType());
if (!(type instanceof ItemTool)) {
return stack;
}
ItemTool toolType = (ItemTool) type;
if (stack.getDurability() > toolType.getMaxDurability()) {
stack.setAmount(0);
}
} else if (target.getType() == Material.TNT) {
BlockTNT.igniteBlock(target, false);
} else {
successful = false;
}
return stack.getAmount() > 0 ? stack : null;
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class GlowChest method getInventory.
@Override
public Inventory getInventory() {
GlowBlock me = getBlock();
BlockChest blockChest = (BlockChest) ItemTable.instance().getBlock(me.getType());
BlockFace attachedChest = blockChest.getAttachedChest(me);
if (attachedChest != null) {
Block nearbyBlock = me.getRelative(attachedChest);
GlowChest nearbyChest = (GlowChest) nearbyBlock.getState();
switch(attachedChest) {
case SOUTH:
case EAST:
return new GlowDoubleChestInventory(this, nearbyChest);
case WEST:
case NORTH:
return new GlowDoubleChestInventory(nearbyChest, this);
default:
GlowServer.logger.warning("GlowChest#getInventory() can only handle N/O/S/W BlockFaces, got " + attachedChest);
return getBlockInventory();
}
}
return getBlockInventory();
}
use of net.glowstone.block.GlowBlock in project Glowstone by GlowstoneMC.
the class GlowPlayer method enterBed.
/**
* This player enters the specified bed and is marked as sleeping.
*
* @param block the bed
*/
public void enterBed(GlowBlock block) {
checkNotNull(block, "Bed block cannot be null");
Preconditions.checkState(bed == null, "Player already in bed");
GlowBlock head = BlockBed.getHead(block);
GlowBlock foot = BlockBed.getFoot(block);
if (EventFactory.callEvent(new PlayerBedEnterEvent(this, head)).isCancelled()) {
return;
}
// Occupy the bed
BlockBed.setOccupied(head, foot, true);
bed = head;
sleeping = true;
setRawLocation(head.getLocation(), false);
getSession().send(new UseBedMessage(SELF_ID, head.getX(), head.getY(), head.getZ()));
UseBedMessage msg = new UseBedMessage(getEntityId(), head.getX(), head.getY(), head.getZ());
world.getRawPlayers().stream().filter(p -> p != this && p.canSeeEntity(this)).forEach(p -> p.getSession().send(msg));
}
use of net.glowstone.block.GlowBlock 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.block.GlowBlock in project Glowstone by GlowstoneMC.
the class GlowLivingEntity method getVelocityFromMovement.
protected Vector getVelocityFromMovement() {
// ensure movement vector is in correct format
movement.setY(0);
double mag = movement.getX() * movement.getX() + movement.getZ() * movement.getZ();
// don't do insignificant movement
if (mag < 0.01) {
return new Vector();
}
// unit vector of movement
movement.setX(movement.getX() / mag);
movement.setZ(movement.getZ() / mag);
// scale to how fast the entity can go
mag *= speed;
Vector movement = this.movement.clone();
movement.multiply(mag);
// make velocity vector relative to where the entity is facing
double yaw = Math.toRadians(location.getYaw());
double z = Math.sin(yaw);
double x = Math.cos(yaw);
movement.setX(movement.getZ() * x - movement.getX() * z);
movement.setZ(movement.getX() * x + movement.getZ() * z);
// apply the movement multiplier
if (!isOnGround() || location.getBlock().isLiquid()) {
// constant multiplier in liquid or not on ground
movement.multiply(0.02);
} else {
this.slipMultiplier = ((GlowBlock) location.getBlock()).getMaterialValues().getSlipperiness();
double slipperiness = slipMultiplier * 0.91;
movement.multiply(0.1 * (0.1627714 / Math.pow(slipperiness, 3)));
}
return movement;
}
Aggregations