/** * Make a patch vine. * * @param basePos the base position * @param pos the vine position */ private void placeVine(Vector basePos, Vector pos) throws MaxChangedBlocksException { if (pos.distance(basePos) > 4) return; if (editSession.getBlockType(pos) != 0) return; for (int i = -1; i > -3; --i) { Vector testPos = pos.add(0, i, 0); if (editSession.getBlockType(testPos) == BlockID.AIR) { pos = testPos; } else { break; } } editSession.setBlockIfAir(pos, new BaseBlock(BlockID.LEAVES)); affected++; int t = random.nextInt(4); int h = random.nextInt(3) - 1; Vector p; BaseBlock log = new BaseBlock(BlockID.LOG); switch (t) { case 0: if (random.nextBoolean()) { placeVine(basePos, pos.add(1, 0, 0)); } if (random.nextBoolean()) { editSession.setBlockIfAir(pos.add(1, h, -1), log); affected++; } editSession.setBlockIfAir(p = pos.add(0, 0, -1), plant.apply(p)); affected++; break; case 1: if (random.nextBoolean()) { placeVine(basePos, pos.add(0, 0, 1)); } if (random.nextBoolean()) { editSession.setBlockIfAir(pos.add(1, h, 0), log); affected++; } editSession.setBlockIfAir(p = pos.add(1, 0, 1), plant.apply(p)); affected++; break; case 2: if (random.nextBoolean()) { placeVine(basePos, pos.add(0, 0, -1)); } if (random.nextBoolean()) { editSession.setBlockIfAir(pos.add(-1, h, 0), log); affected++; } editSession.setBlockIfAir(p = pos.add(-1, 0, 1), plant.apply(p)); affected++; break; case 3: if (random.nextBoolean()) { placeVine(basePos, pos.add(-1, 0, 0)); } if (random.nextBoolean()) { editSession.setBlockIfAir(pos.add(-1, h, -1), log); affected++; } editSession.setBlockIfAir(p = pos.add(-1, 0, -1), plant.apply(p)); affected++; break; } }
@Override public BaseBlock apply(Vector pos) { mutable.y = pos.y; mutable.z = pos.z; return pattern.apply(mutable); }