public Vector3i add(Vector3i v) { return add(v.x, v.y, v.z); }
public Vector3i add(Vector3i v) { return add(v.x, v.y, v.z); }
public BlockBuffer(Vector3i min, Vector3i max) { this.min = min; this.max = max; this.size = this.max.sub(this.min).add(1, 1, 1); this.buffer = new char[this.size.getX() * this.size.getY() * this.size.getZ()]; Arrays.fill(this.buffer, Character.MAX_VALUE); }
public Vector3i add(double x, double y, double z) { return add(GenericMath.floor(x), GenericMath.floor(y), GenericMath.floor(z)); }
public Vector3i add(double x, double y, double z) { return add(GenericMath.floor(x), GenericMath.floor(y), GenericMath.floor(z)); }
public static boolean isEntityInLocation(Location<World> location, Entity entity) { AABB boundingBox = entity.getBoundingBox().orElse(null); return boundingBox != null && boundingBox.intersects(new AABB(location.getBlockPosition(), location.getBlockPosition().add(1, 1, 1))); }
public BlockOperation(CachedWorld world, Vector3i min, Vector3i max) { super(null); this.blockService = WebAPI.getBlockService(); this.uuid = UUID.randomUUID(); this.world = world; this.min = min; this.max = max; this.size = max.sub(min).add(1, 1, 1); this.cause = Cause.of(EventContext.empty(), WebAPI.getContainer()); this.totalBlocks = size.getX() * size.getY() * size.getZ(); }
@Override public BehaviorResult handleItemInteraction(Server server, Player player, Vector3i against, BlockFace face, ItemStack withItem) { if (withItem.getItemType() == ItemTypes.DIAMOND_HOE || withItem.getItemType() == ItemTypes.GOLDEN_HOE || withItem.getItemType() == ItemTypes.IRON_HOE || withItem.getItemType() == ItemTypes.STONE_HOE || withItem.getItemType() == ItemTypes.WOODEN_HOE) { Vector3i adjusted = against.add(face.getOffset()); Optional<Block> originalBlockOptional = player.getLevel().getBlockIfChunkLoaded(adjusted); if (!originalBlockOptional.isPresent()) { return BehaviorResult.NOTHING; } if (BehaviorUtils.replaceBlockState(player, originalBlockOptional.get(), new BasicBlockState(BlockTypes.FARMLAND, null, null))) { return BehaviorResult.REDUCE_DURABILITY; } else { return BehaviorResult.NOTHING; } } return super.handleItemInteraction(server, player, against, face, withItem); }
while ((toRemove = remove.poll()) != null) { computeRemoveBlockLight(toRemove.data.sub(1, 0, 0), toRemove.light, remove, spread, visitedRemove, visitedSpread); computeRemoveBlockLight(toRemove.data.add(1, 0, 0), toRemove.light, remove, spread, visitedRemove, visitedSpread); computeRemoveBlockLight(toRemove.data.sub(0, 1, 0), toRemove.light, remove, spread, visitedRemove, visitedSpread); computeRemoveBlockLight(toRemove.data.add(0, 1, 0), toRemove.light, remove, spread, visitedRemove, visitedSpread); computeRemoveBlockLight(toRemove.data.sub(0, 0, 1), toRemove.light, remove, spread, visitedRemove, visitedSpread); computeRemoveBlockLight(toRemove.data.add(0, 0, 1), toRemove.light, remove, spread, visitedRemove, visitedSpread); computeSpreadBlockLight(toSpread.add(1, 0, 0), adjustedLight, spread, visitedSpread); computeSpreadBlockLight(toSpread.sub(0, 1, 0), adjustedLight, spread, visitedSpread); computeSpreadBlockLight(toSpread.add(0, 1, 0), adjustedLight, spread, visitedSpread); computeSpreadBlockLight(toSpread.sub(0, 0, 1), adjustedLight, spread, visitedSpread); computeSpreadBlockLight(toSpread.add(0, 0, 1), adjustedLight, spread, visitedSpread);
@Override public BehaviorResult handleItemInteraction(Server server, Player player, Vector3i against, BlockFace face, ItemStack withItem) { if (face == BlockFace.TOP) { Vector3i adjusted = against.add(face.getOffset()); Optional<Block> originalBlockOptional = player.getLevel().getBlockIfChunkLoaded(adjusted); if (!originalBlockOptional.isPresent()) { return BehaviorResult.NOTHING; } // If a block is already on the farmland, don't proceed. if (originalBlockOptional.get().getBlockState().getBlockType() != BlockTypes.AIR) { return BehaviorResult.NOTHING; } // Seeds if (withItem.getItemType() == ItemTypes.SEEDS) { return BehaviorUtils.setBlockState(player, adjusted, new BasicBlockState(BlockTypes.CROPS, Crops.NEW, null)) ? BehaviorResult.REMOVE_ONE_ITEM : BehaviorResult.NOTHING; } // TODO: Other seeds if (withItem.getItemType().isBlock()) { // Destroy the farmland. if (BehaviorUtils.replaceBlockState(player, originalBlockOptional.get(), new BasicBlockState(BlockTypes.DIRT, null, null))) { return BehaviorResult.PLACE_BLOCK_AND_REMOVE_ITEM; } else { return BehaviorResult.NOTHING; } } } return super.handleItemInteraction(server, player, against, face, withItem); }
int y = (currentBlock - x * size.getY() * size.getZ()) / size.getZ(); int z = currentBlock - x * size.getY() * size.getZ() - y * size.getZ(); Vector3i pos = new Vector3i(x, y, z).add(min);
@Override public BehaviorResult handleItemInteraction(Server server, Player player, Vector3i against, BlockFace face, ItemStack withItem) { if (withItem != null) { if (withItem.getItemType() == BlockTypes.TOP_SNOW) { Vector3i adjusted = against.add(face.getOffset()); Optional<Block> originalBlockOptional = player.getLevel().getBlockIfChunkLoaded(adjusted); if (!originalBlockOptional.isPresent()) { return BehaviorResult.NOTHING; } // Add another layer to the snow block if needed Block againstBlock = originalBlockOptional.get(); if (againstBlock.getBlockState().getBlockType() == BlockTypes.TOP_SNOW && againstBlock.getBlockState().getBlockData() instanceof TopSnow) { int layer = ((TopSnow) againstBlock.getBlockState().getBlockData()).getLayers(); if (layer >= 7) { // Need to place a new block down. return BehaviorResult.PLACE_BLOCK_AND_REMOVE_ITEM; } else { BlockState newBlockState = new BasicBlockState(BlockTypes.TOP_SNOW, TopSnow.of(layer + 1), null); return BehaviorUtils.replaceBlockState(player, againstBlock, newBlockState) ? BehaviorResult.REMOVE_ONE_ITEM : BehaviorResult.NOTHING; } } } } return super.handleItemInteraction(server, player, against, face, withItem); }
case PLACE_BLOCK_AND_REMOVE_ITEM: Preconditions.checkState(serverInHand != null && serverInHand.getItemType() instanceof BlockType, "Tried to place air or non-block."); if (!BehaviorUtils.setBlockState(PlayerSession.this, packet.getLocation().add(face.getOffset()), BehaviorUtils.createBlockState(usedAgainst.get().getLevelLocation(), face, serverInHand))) { sendPlayerInventory(); return;
Vector3i size = max.sub(min).add(1, 1, 1); int numBlocks = size.getX() * size.getY() * size.getZ();
private void testMutableBuffer(MutableBiomeVolume buffer) { final Vector3i min = buffer.getBiomeMin(); final Vector3i max = buffer.getBiomeMax(); // Test bound validation try { buffer.setBiome(min.sub(1, 0, 0), BiomeTypes.SKY); Assert.fail(); } catch (PositionOutOfBoundsException ignored) { } try { buffer.setBiome(max.add(1, 0, 0), BiomeTypes.SKY); Assert.fail(); } catch (PositionOutOfBoundsException ignored) { } // Test fill for (int x = min.getX(); x <= max.getX(); x++) { for (int z = min.getZ(); z <= max.getZ(); z++) { final BiomeType randomBiome = getRandomBiome(); buffer.setBiome(x, 0, z, randomBiome); Assert.assertEquals(randomBiome, buffer.getBiome(x, 0, z)); } } }
private void testMutableBuffer(MutableBlockVolume buffer) { final Vector3i min = buffer.getBlockMin(); final Vector3i max = buffer.getBlockMax(); // Test bound validation try { buffer.getBlock(min.sub(1, 0, 0)); Assert.fail(); } catch (PositionOutOfBoundsException ignored) { } try { buffer.getBlock(max.add(1, 0, 0)); Assert.fail(); } catch (PositionOutOfBoundsException ignored) { } // Test fill for (int x = min.getX(); x <= max.getX(); x++) { for (int y = min.getY(); y <= max.getY(); y++) { for (int z = min.getZ(); z <= max.getZ(); z++) { final BlockState randomBlock = getRandomBlock(); buffer.setBlock(x, y, z, randomBlock); Assert.assertEquals(randomBlock, buffer.getBlock(x, y, z)); } } } }
buffer.getBiome(max.add(1, 0, 0)); Assert.fail(); } catch (PositionOutOfBoundsException ignored) {
buffer.getBlock(max.add(1, 0, 0)); Assert.fail(); } catch (PositionOutOfBoundsException ignored) {