@Override public int onUpdate(int type) { if (type == Level.BLOCK_UPDATE_NORMAL) { Block below = this.getSide(0); int side = this.getDamage(); int[] faces = new int[] { 0, // 0 4, // 1 5, // 2 2, // 3 3, // 4 0, // 5 0 // 6 }; if (this.getSide(faces[side]).isTransparent() && !(side == 0 && (below instanceof BlockFence || below.getId() == COBBLE_WALL))) { this.getLevel().useBreakOn(this); return Level.BLOCK_UPDATE_NORMAL; } } return 0; }
private void writeTracker(Block block) { synchronized (this) { checkUpdate(Write); Long id = block.getId(); add(Write, id); if (!activeWriteBlocks.contains(id)) error(Write, id + " is not an active write block"); } }
@Override public boolean place( Item item, Block block, Block target, int face, double fx, double fy, double fz, Player player) { Block down = this.getSide(Vector3.SIDE_DOWN); if (down.getId() == Block.GRASS || down.getId() == Block.DIRT || down.getId() == Block.PODZOL) { this.getLevel().setBlock(block, this, true); return true; } return false; }
@Override public void release(Block block) { synchronized (this) { checkReadOrIter(Release); Long id = block.getId(); add(Release, id); if (!activeReadBlocks.contains(id) && !activeIterBlocks.contains(id) && !activeWriteBlocks.contains(id)) error(Release, id + " is not an active block"); // May have been promoted. if (activeWriteBlocks.contains(id)) activeWriteBlocks.remove(id); else activeReadBlocks.remove(block.getId()); activeIterBlocks.remove(block.getId()); } blockMgr.release(block); }
@Override public long getBlockIdAtHeight(int height) { Block block = lastBlock.get(); if (height > block.getHeight()) { throw new IllegalArgumentException( "Invalid height " + height + ", current blockchain is at " + block.getHeight()); } if (height == block.getHeight()) { return block.getId(); } return BlockDb.findBlockIdAtHeight(height); }
@Override public void free(Block block) { synchronized (this) { checkUpdate(Free); Long id = block.getId(); add(Free, id); if (activeReadBlocks.contains(id)) error(Free, id + " is a read block"); else if (!activeWriteBlocks.contains(id)) error(Free, id + " is not a write block"); activeWriteBlocks.remove(id); } blockMgr.free(block); }
@Override public Block allocate(int blockSize) { Block block; synchronized (this) { checkUpdate(Alloc); block = blockMgr.allocate(blockSize); Long id = block.getId(); activeWriteBlocks.add(id); add(Alloc, id); } return block; }
@Override public Block promote(Block block) { synchronized (this) { checkUpdate(Promote); Long id = block.getId(); add(Promote, id); if (!activeWriteBlocks.contains(id) && !activeReadBlocks.contains(id)) error(Promote, id + " is not an active block"); if (activeReadBlocks.contains(id)) // Remove one read count // Really, do this if obtained via "getRead" and not "getWrite" activeReadBlocks.remove(id); // Double promotion results in only one entry. if (!activeWriteBlocks.contains(id)) activeWriteBlocks.add(id); } return blockMgr.promote(block); }
/** * Create a ledger entry * * @param event Event * @param eventId Event identifier * @param accountId Account identifier * @param holding Holding or null * @param holdingId Holding identifier or null * @param change Change in balance * @param balance New balance */ public LedgerEntry( LedgerEvent event, long eventId, long accountId, LedgerHolding holding, Long holdingId, long change, long balance) { this.event = event; this.eventId = eventId; this.accountId = accountId; this.holding = holding; this.holdingId = holdingId; this.change = change; this.balance = balance; Block block = blockchain.getLastBlock(); this.blockId = block.getId(); this.height = block.getHeight(); this.timestamp = block.getTimestamp(); }
@Override public boolean place( Item item, Block block, Block target, int face, double fx, double fy, double fz, Player player) { Block below = this.getSide(0); if (!target.isTransparent() && face != 0) { int[] faces = new int[] { 0, // 0, nerver used 5, // 1 4, // 2 3, // 3 2, // 4 1, // 5 }; this.meta = faces[face]; this.getLevel().setBlock(block, this, true, true); return true; } else if (!below.isTransparent() || below instanceof BlockFence || below.getId() == COBBLE_WALL) { this.meta = 0; this.getLevel().setBlock(block, this, true, true); return true; } return false; }
public boolean canConnect(Block block) { return (!(block.getId() != COBBLE_WALL && block.getId() != FENCE_GATE)) || block.isSolid() && !block.isTransparent(); }
@Override public void s_() { K(); BlockPosition blockposition = new BlockPosition(locX, locY, locZ); IBlockData iblockdata = world.getType(blockposition); Block block = iblockdata.getBlock(); if (!ignoredMaterials.contains(Material.getMaterial(Block.getId(block)))) { AxisAlignedBB axisalignedbb = block.a(world, blockposition, iblockdata); if ((axisalignedbb != null) && (axisalignedbb.a(new Vec3D(locX, locY, locZ)))) { float damageMultiplier = MathHelper.sqrt(motX * motX + motY * motY + motZ * motZ); CustomProjectileHitEvent event = new ItemProjectileHitEvent( this, damageMultiplier, world.getWorld().getBlockAt((int) locX, (int) locY, (int) locZ), BlockFace.UP, getItem()); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { die(); } } } age += 1; Vec3D vec3d = new Vec3D(locX, locY, locZ); Vec3D vec3d1 = new Vec3D(locX + motX, locY + motY, locZ + motZ); MovingObjectPosition movingobjectposition = world.rayTrace(vec3d, vec3d1, false, true, false); vec3d = new Vec3D(locX, locY, locZ); vec3d1 = new Vec3D(locX + motX, locY + motY, locZ + motZ); if (movingobjectposition != null) { vec3d1 = new Vec3D( movingobjectposition.pos.a, movingobjectposition.pos.b, movingobjectposition.pos.c); } Entity entity = null; List list = world.getEntities(this, getBoundingBox().a(motX, motY, motZ).grow(1.0D, 1.0D, 1.0D)); double d0 = 0.0D; for (Object aList : list) { Entity entity1 = (Entity) aList; if ((entity1.ad()) && ((entity1 != shooter) || (age >= 5))) { float f1 = 0.3F; AxisAlignedBB axisalignedbb1 = entity1.getBoundingBox().grow(f1, f1, f1); MovingObjectPosition movingobjectposition1 = axisalignedbb1.a(vec3d, vec3d1); if (movingobjectposition1 != null) { double d1 = vec3d.distanceSquared(movingobjectposition1.pos); if ((d1 < d0) || (d0 == 0.0D)) { entity = entity1; d0 = d1; } } } } if (entity != null) { movingobjectposition = new MovingObjectPosition(entity); } if ((movingobjectposition != null) && (movingobjectposition.entity != null) && ((movingobjectposition.entity instanceof EntityHuman))) { EntityHuman entityhuman = (EntityHuman) movingobjectposition.entity; if ((entityhuman.abilities.isInvulnerable) || (((shooter instanceof EntityHuman)) && (!((EntityHuman) shooter).a(entityhuman)))) { movingobjectposition = null; } } if (movingobjectposition != null) { if (movingobjectposition.entity != null && movingobjectposition.entity instanceof EntityLiving) { float damageMultiplier = MathHelper.sqrt(motX * motX + motY * motY + motZ * motZ); CustomProjectileHitEvent event = new ItemProjectileHitEvent( this, damageMultiplier, (LivingEntity) movingobjectposition.entity.getBukkitEntity(), getItem()); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { if (getKnockback() > 0) { float f4 = MathHelper.sqrt(motX * motX + motZ * motZ); if (f4 > 0.0F) { movingobjectposition.entity.g( motX * getKnockback() * 0.6000000238418579D / f4, 0.1D, motZ * getKnockback() * 0.6000000238418579D / f4); } } die(); } } else if (movingobjectposition.a() != null) { if (!ignoredMaterials.contains(Material.getMaterial(Block.getId(block)))) { motX = ((float) (movingobjectposition.pos.a - locX)); motY = ((float) (movingobjectposition.pos.b - locY)); motZ = ((float) (movingobjectposition.pos.c - locZ)); float f3 = MathHelper.sqrt(motX * motX + motY * motY + motZ * motZ); locX -= motX / f3 * 0.0500000007450581D; locY -= motY / f3 * 0.0500000007450581D; locZ -= motZ / f3 * 0.0500000007450581D; float damageMultiplier = MathHelper.sqrt(motX * motX + motY * motY + motZ * motZ); CustomProjectileHitEvent event = new ItemProjectileHitEvent( this, damageMultiplier, world .getWorld() .getBlockAt( (int) movingobjectposition.pos.a, (int) movingobjectposition.pos.b, (int) movingobjectposition.pos.c), CraftBlock.notchToBlockFace(movingobjectposition.direction), getItem()); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { die(); } } } } locX += motX; locY += motY; locZ += motZ; float f3 = 0.99F; float f1 = 0.05F; motX *= f3; motY *= f3; motZ *= f3; motY -= f1; setPosition(locX, locY, locZ); checkBlockCollisions(); if (isAlive()) { if (this.age >= 1000) { die(); } for (Runnable r : runnables) { r.run(); } for (TypedRunnable<ItemProjectile> r : typedRunnables) { r.run(this); } } }
public byte getBlockIdFor(Side attachmentSide, Side direction) { Block block = getBlockFor(attachmentSide, direction); return (block != null) ? block.getId() : 0; }
public Block getBlock(Long blockId) { for (Block block : blocks) if (block.getId().equals(blockId)) return block; return null; }
public String getDefaultTexPath() { return "/tex/block/".concat(block.getId()).concat(".png"); }