public Material getTrackedTreeMaterial(String trackedType) { if (Material.CHORUS_PLANT.toString().equals(trackedType)) return Material.CHORUS_PLANT; else { for (TreeType treeType : TreeType.values()) { if (treeType.toString().equals(trackedType)) { if (treeType == TreeType.ACACIA || treeType == TreeType.DARK_OAK) return Material.LOG_2; else if (treeType == TreeType.BROWN_MUSHROOM) return Material.HUGE_MUSHROOM_1; else if (treeType == TreeType.RED_MUSHROOM) return Material.HUGE_MUSHROOM_2; else return Material.LOG; } } } CropControl.getPlugin().debug("Unable to match tracked tree type material {0}", trackedType); return null; }
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { world.captureTreeGeneration = true; world.captureBlockStates = true; boolean grownTree = generateTree(loc, type); world.captureBlockStates = false; world.captureTreeGeneration = false; if (grownTree) { // Copy block data to delegate for (BlockState blockstate : world.capturedBlockStates) { int x = blockstate.getX(); int y = blockstate.getY(); int z = blockstate.getZ(); net.minecraft.server.Block oldBlock = world.getType(x, y, z); int typeId = blockstate.getTypeId(); int data = blockstate.getRawData(); int flag = ((CraftBlockState)blockstate).getFlag(); delegate.setTypeIdAndData(x, y, z, typeId, data); net.minecraft.server.Block newBlock = world.getType(x, y, z); world.notifyAndUpdatePhysics(x, y, z, null, oldBlock, newBlock, flag); } world.capturedBlockStates.clear(); return true; } else { world.capturedBlockStates.clear(); return false; } }
public boolean grow(World world, int i, int j, int k, Random random) { int l = world.getData(i, j, k); world.setAir(i, j, k); WorldGenHugeMushroom worldgenhugemushroom = null; if (this == Blocks.BROWN_MUSHROOM) { BlockSapling.treeType = TreeType.BROWN_MUSHROOM; // CraftBukkit worldgenhugemushroom = new WorldGenHugeMushroom(0); } else if (this == Blocks.RED_MUSHROOM) { BlockSapling.treeType = TreeType.RED_MUSHROOM; // CraftBukkit worldgenhugemushroom = new WorldGenHugeMushroom(1); } if (worldgenhugemushroom != null && worldgenhugemushroom.generate(world, random, i, j, k)) { return true; } else { world.setTypeAndData(i, j, k, this, l, 3); return false; } }
@SuppressWarnings("deprecation") private TreeType getTree(Block block) { if (block.getType() == Material.SAPLING) { switch (block.getData()) { case 0: return TreeType.TREE; case 1: return TreeType.REDWOOD; case 2: return TreeType.BIRCH; case 3: return TreeType.SMALL_JUNGLE; case 4: return TreeType.ACACIA; case 5: return TreeType.DARK_OAK; } return TreeType.TREE; } else { if (block.getType() == Material.BROWN_MUSHROOM) { return TreeType.BROWN_MUSHROOM; } else { return TreeType.RED_MUSHROOM; } } }
public TreeType rollTreeType(Random random) { double total = 0.0; for(int i = 0; i < treeTypeChance.length; i++) { total += treeTypeChance[i]; } double d = random.nextDouble()*total; double chance = 0.0; for(int i = 0; i < treeType.length; i++) { if(d < chance+treeTypeChance[i]) { return treeType[i]; } else { chance += treeTypeChance[i]; } } return TreeType.TREE; }
@Override public boolean use(Player player) { Block targetBlock = getTargetBlock(player, null, 32); boolean successful = targetBlock.getWorld().generateTree(targetBlock.getRelative(BlockFace.UP).getLocation(), TreeType.JUNGLE); if (successful) { for (LivingEntity entity : player.getWorld().getLivingEntities()) { if (entity.getLocation().distanceSquared(targetBlock.getLocation()) <= 256) { double damage = 15D; EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(player, entity, EntityDamageEvent.DamageCause.MAGIC, new EnumMap(ImmutableMap.of(EntityDamageEvent.DamageModifier.BASE, Double.valueOf(damage))), new EnumMap(ImmutableMap.of(EntityDamageEvent.DamageModifier.BASE, ZERO))); Bukkit.getPluginManager().callEvent(event); if (!event.isCancelled()) { if (event.getEntity() instanceof LivingEntity) { ((LivingEntity) event.getEntity()).damage(event.getDamage(), event.getDamager()); event.getEntity().setLastDamageCause(event); } } } } } else { player.sendMessage(ChatColor.RED + "Could not grow a tree there."); } return successful; }
public boolean c(World world, BlockPosition blockposition, IBlockData iblockdata, Random random) { world.setAir(blockposition); WorldGenHugeMushroom worldgenhugemushroom = null; if (this == Blocks.BROWN_MUSHROOM) { BlockSapling.treeType = TreeType.BROWN_MUSHROOM; // CraftBukkit worldgenhugemushroom = new WorldGenHugeMushroom(Blocks.BROWN_MUSHROOM_BLOCK); } else if (this == Blocks.RED_MUSHROOM) { BlockSapling.treeType = TreeType.RED_MUSHROOM; // CraftBukkit worldgenhugemushroom = new WorldGenHugeMushroom(Blocks.RED_MUSHROOM_BLOCK); } if (worldgenhugemushroom != null && worldgenhugemushroom.generate(world, random, blockposition)) { return true; } else { world.setTypeAndData(blockposition, iblockdata, 3); return false; } }
@Override public void run(final IUser user, final String commandLabel, final String[] args) throws Exception { final BigTree bigTree = BIGTREE_PARSER.parse(args).getValue(); final TreeType bukkitTree = bigTree.getBukkitType(); final Location loc = LocationUtil.getTarget(user.getPlayer()); final Location safeLocation = LocationUtil.getSafeDestination(loc); final boolean success = user.getPlayer().getWorld().generateTree(safeLocation, bukkitTree); if (success) { user.sendMessage(_("§6Big tree spawned.")); } else { throw new Exception(_("§4Big tree generation failure. Try again on grass or dirt.")); } }
public Material getTrackedTypeMaterial(String trackedType) { for (Material material : harvestableCrops.keySet()) { if (material.toString().equals(trackedType)) return material; } if (Material.MELON_BLOCK.toString().equals(trackedType)) return Material.MELON_BLOCK; else if (Material.PUMPKIN.toString().equals(trackedType)) return Material.PUMPKIN; for (Byte i = 0; i < 6; i++) { if (getSaplingType(i).equals(trackedType)) // TODO: odd structure here return Material.SAPLING; } for (TreeType treeType : TreeType.values()) { if (treeType.toString().equals(trackedType)) { if (treeType == TreeType.ACACIA || treeType == TreeType.DARK_OAK) return Material.LOG_2; else if (treeType == TreeType.BROWN_MUSHROOM) return Material.HUGE_MUSHROOM_1; else if (treeType == TreeType.RED_MUSHROOM) return Material.HUGE_MUSHROOM_2; else return Material.LOG; } } if (Material.CHORUS_PLANT.toString().equals(trackedType)) return Material.CHORUS_PLANT; CropControl.getPlugin().debug("Unable to match tracked type material {0}", trackedType); return null; }
public StructureGrowEvent(final Location location, final TreeType species, final boolean bonemeal, final Player player, final List<BlockState> blocks) { super(location.getWorld()); this.location = location; this.species = species; this.bonemeal = bonemeal; this.player = player; this.blocks = blocks; }
@Override public void take(Protocol.Report report) { final Player p = getPlayer(); if (p != null) { if (InteractivePlugin.INSTANCE != null) { Bukkit.getScheduler().runTaskLater(InteractivePlugin.INSTANCE, new Runnable() { @Override public void run() { Location position = PositionUtil.getSafeLocationWithin(p, 2, 5); if (position == null) { position = PositionUtil.getLocationWithin(p, 4, 6); } Block block = p.getWorld().getBlockAt(position); if ((block.getType() != Material.DIRT) || (block.getType() != Material.GRASS)) { block.setType(Material.DIRT); position.add(0, 1, 0); } p.getWorld().generateTree(position, TreeType.TREE); StringBuffer buffer = new StringBuffer(); buffer.append(ChatColor.GRAY); buffer.append(ChatColor.ITALIC); buffer.append("A Wild Tree Appears!"); getPlayer().sendMessage(buffer.toString()); } }, 1); } } }
@Override public boolean generateTree(final Location location, final TreeType type) { return TaskManager.IMP.sync(new RunnableVal<Boolean>() { @Override public void run(Boolean value) { this.value = parent.generateTree(location, type); } }); }
@Override public boolean generateTree(final Location loc, final TreeType type, final BlockChangeDelegate delegate) { return TaskManager.IMP.sync(new RunnableVal<Boolean>() { @Override public void run(Boolean value) { this.value = parent.generateTree(loc, type, delegate); } }); }
@Override public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) { World world = getWorld(); TreeType bukkitType = toBukkitTreeType(type); return type != null && world.generateTree(BukkitUtil.toLocation(world, pt), bukkitType, new EditSessionBlockChangeDelegate(editSession)); }
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { world.captureTreeGeneration = true; world.captureBlockStates = true; boolean grownTree = generateTree(loc, type); world.captureBlockStates = false; world.captureTreeGeneration = false; if (grownTree) { // Copy block data to delegate for (BlockState blockstate : world.capturedBlockStates) { int x = blockstate.getX(); int y = blockstate.getY(); int z = blockstate.getZ(); BlockPosition position = new BlockPosition(x, y, z); net.minecraft.server.Block oldBlock = world.getType(position).getBlock(); int typeId = blockstate.getTypeId(); int data = blockstate.getRawData(); int flag = ((CraftBlockState)blockstate).getFlag(); delegate.setTypeIdAndData(x, y, z, typeId, data); net.minecraft.server.Block newBlock = world.getType(position).getBlock(); world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, flag); } world.capturedBlockStates.clear(); return true; } else { world.capturedBlockStates.clear(); return false; } }
@Override public boolean grow(Block block) { if (block.getType() != Material.SAPLING && block.getType() != Material.BROWN_MUSHROOM && block.getType() != Material.RED_MUSHROOM) return false; TreeType type = getTree(block); Material prevMat = block.getType(); block.setType(Material.AIR); if (block.getWorld().generateTree(block.getLocation(), type)) { return true; } block.setType(prevMat); return false; }
@Operation(desc = "Grow a tree of the given type on top of this block. Returns 1 uppon success, 0 otherwise.") public static Parameter growtreeOperation(org.bukkit.block.Block block, Context ctx, StringParameter type) { TreeType t = TreeType.TREE; if ( type != null ) t = type.asEnum(TreeType.class); if ( t == null ) fizzle("No such tree type: " + type.asString()); return Parameter.from(block.getWorld().generateTree(block.getLocation().add(0, 1.0, 0), t) ? 1 : 0); }
@Override public void animate(Fight fight, Character attacking, Character defending, ItemStack weapon) { Player defendingPlayer = defending.getPlayer().getPlayer(); defendingPlayer.getWorld().generateTree(defendingPlayer.getLocation(), TreeType.JUNGLE); defendingPlayer.getWorld().getBlockAt(defendingPlayer.getLocation()).setType(Material.AIR); defendingPlayer.getWorld().getBlockAt(defendingPlayer.getEyeLocation()).setType(Material.AIR); }
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { world.captureTreeGeneration = true; world.captureBlockStates = true; boolean grownTree = generateTree(loc, type); world.captureBlockStates = false; world.captureTreeGeneration = false; if (grownTree) { // Copy block data to delegate for (BlockState blockstate : world.capturedBlockStates) { int x = blockstate.getX(); int y = blockstate.getY(); int z = blockstate.getZ(); BlockPosition position = new BlockPosition(x, y, z); net.minecraft.server.IBlockData oldBlock = world.getType(position); int typeId = blockstate.getTypeId(); int data = blockstate.getRawData(); int flag = ((CraftBlockState)blockstate).getFlag(); delegate.setTypeIdAndData(x, y, z, typeId, data); net.minecraft.server.IBlockData newBlock = world.getType(position); world.notifyAndUpdatePhysics(position, null, oldBlock, newBlock, flag); } world.capturedBlockStates.clear(); return true; } else { world.capturedBlockStates.clear(); return false; } }
public boolean generateTree(Location loc, TreeType type) { net.minecraft.world.gen.feature.WorldGenerator gen; switch (type) { case BIG_TREE: gen = new net.minecraft.world.gen.feature.WorldGenBigTree(true); break; case BIRCH: gen = new net.minecraft.world.gen.feature.WorldGenForest(true, false); break; case REDWOOD: gen = new net.minecraft.world.gen.feature.WorldGenTaiga2(true); break; case TALL_REDWOOD: gen = new net.minecraft.world.gen.feature.WorldGenTaiga1(); break; case JUNGLE: gen = new net.minecraft.world.gen.feature.WorldGenMegaJungle(true, 10, 20, 3, 3); // Magic values as in BlockSapling break; case SMALL_JUNGLE: gen = new net.minecraft.world.gen.feature.WorldGenTrees(true, 4 + rand.nextInt(7), 3, 3, false); break; case COCOA_TREE: gen = new net.minecraft.world.gen.feature.WorldGenTrees(true, 4 + rand.nextInt(7), 3, 3, true); break; case JUNGLE_BUSH: gen = new net.minecraft.world.gen.feature.WorldGenShrub(3, 0); break; case RED_MUSHROOM: gen = new net.minecraft.world.gen.feature.WorldGenBigMushroom(1); break; case BROWN_MUSHROOM: gen = new net.minecraft.world.gen.feature.WorldGenBigMushroom(0); break; case SWAMP: gen = new net.minecraft.world.gen.feature.WorldGenSwamp(); break; case ACACIA: gen = new net.minecraft.world.gen.feature.WorldGenSavannaTree(true); break; case DARK_OAK: gen = new net.minecraft.world.gen.feature.WorldGenCanopyTree(true); break; case MEGA_REDWOOD: gen = new net.minecraft.world.gen.feature.WorldGenMegaPineTree(true, rand.nextBoolean()); break; case TALL_BIRCH: gen = new net.minecraft.world.gen.feature.WorldGenForest(true, true); break; case TREE: default: gen = new net.minecraft.world.gen.feature.WorldGenTrees(true); break; } return gen.generate(world, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); }
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { net.minecraft.world.gen.feature.WorldGenerator gen; switch (type) { case BIG_TREE: gen = new net.minecraft.world.gen.feature.WorldGenBigTree(true); break; case BIRCH: gen = new net.minecraft.world.gen.feature.WorldGenForest(true, false); break; case REDWOOD: gen = new net.minecraft.world.gen.feature.WorldGenTaiga2(true); break; case TALL_REDWOOD: gen = new net.minecraft.world.gen.feature.WorldGenTaiga1(); break; case JUNGLE: gen = new net.minecraft.world.gen.feature.WorldGenMegaJungle(true, 10, 20, 3, 3); // Magic values as in BlockSapling break; case SMALL_JUNGLE: gen = new net.minecraft.world.gen.feature.WorldGenTrees(true, 4 + rand.nextInt(7), 3, 3, false); break; case JUNGLE_BUSH: gen = new net.minecraft.world.gen.feature.WorldGenShrub(3, 0); break; case RED_MUSHROOM: gen = new net.minecraft.world.gen.feature.WorldGenBigMushroom(1); break; case BROWN_MUSHROOM: gen = new net.minecraft.world.gen.feature.WorldGenBigMushroom(0); break; case SWAMP: gen = new net.minecraft.world.gen.feature.WorldGenSwamp(); break; case ACACIA: gen = new net.minecraft.world.gen.feature.WorldGenSavannaTree(true); break; case DARK_OAK: gen = new net.minecraft.world.gen.feature.WorldGenCanopyTree(true); break; case MEGA_REDWOOD: gen = new net.minecraft.world.gen.feature.WorldGenMegaPineTree(true, rand.nextBoolean()); break; case TALL_BIRCH: gen = new net.minecraft.world.gen.feature.WorldGenForest(true, true); break; case TREE: default: gen = new net.minecraft.world.gen.feature.WorldGenTrees(true); break; } CaptureTree tCapture=world.mCapture.startTreeGenCapture(null,loc); boolean grownTree = gen.generate(world, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); tCapture.markHandled(); if (grownTree) { // Copy block data to delegate for (BlockSnapshot blocksnapshot : tCapture.mCapturedBlocks) { int x = blocksnapshot.x; int y = blocksnapshot.y; int z = blocksnapshot.z; net.minecraft.block.Block oldBlock = world.getBlock(x, y, z); int newId = net.minecraft.block.Block.getIdFromBlock(blocksnapshot.replacedBlock); int data = blocksnapshot.meta; int flag = blocksnapshot.flag; delegate.setTypeIdAndData(x, y, z, newId, data); net.minecraft.block.Block newBlock = world.getBlock(x, y, z); world.markAndNotifyBlock(x, y, z, null, oldBlock, newBlock, flag); } return true; } else { return false; } }
@Override public boolean generateTree(Location location, TreeType type) { // TODO Auto-generated method stub throw new UnimplementedOperationException(); }
@Override public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { // TODO Auto-generated method stub throw new UnimplementedOperationException(); }
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { net.minecraft.world.gen.feature.WorldGenerator gen; switch (type) { case BIG_TREE: gen = new net.minecraft.world.gen.feature.WorldGenBigTree(true); break; case BIRCH: gen = new net.minecraft.world.gen.feature.WorldGenForest(true, false); break; case REDWOOD: gen = new net.minecraft.world.gen.feature.WorldGenTaiga2(true); break; case TALL_REDWOOD: gen = new net.minecraft.world.gen.feature.WorldGenTaiga1(); break; case JUNGLE: gen = new net.minecraft.world.gen.feature.WorldGenMegaJungle(true, 10, 20, 3, 3); // Magic values as in BlockSapling break; case SMALL_JUNGLE: gen = new net.minecraft.world.gen.feature.WorldGenTrees(true, 4 + rand.nextInt(7), 3, 3, false); break; case JUNGLE_BUSH: gen = new net.minecraft.world.gen.feature.WorldGenShrub(3, 0); break; case RED_MUSHROOM: gen = new net.minecraft.world.gen.feature.WorldGenBigMushroom(1); break; case BROWN_MUSHROOM: gen = new net.minecraft.world.gen.feature.WorldGenBigMushroom(0); break; case SWAMP: gen = new net.minecraft.world.gen.feature.WorldGenSwamp(); break; case ACACIA: gen = new net.minecraft.world.gen.feature.WorldGenSavannaTree(true); break; case DARK_OAK: gen = new net.minecraft.world.gen.feature.WorldGenCanopyTree(true); break; case MEGA_REDWOOD: gen = new net.minecraft.world.gen.feature.WorldGenMegaPineTree(true, rand.nextBoolean()); break; case TALL_BIRCH: gen = new net.minecraft.world.gen.feature.WorldGenForest(true, true); break; case TREE: default: gen = new net.minecraft.world.gen.feature.WorldGenTrees(true); break; } world.captureTreeGeneration = true; world.captureBlockSnapshots = true; boolean grownTree = gen.generate(world, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()); world.captureBlockSnapshots = false; world.captureTreeGeneration = false; if (grownTree) { // Copy block data to delegate for (BlockSnapshot blocksnapshot : world.capturedBlockSnapshots) { int x = blocksnapshot.x; int y = blocksnapshot.y; int z = blocksnapshot.z; net.minecraft.block.Block oldBlock = world.getBlock(x, y, z); int newId = net.minecraft.block.Block.getIdFromBlock(blocksnapshot.replacedBlock); int data = blocksnapshot.meta; int flag = blocksnapshot.flag; delegate.setTypeIdAndData(x, y, z, newId, data); net.minecraft.block.Block newBlock = world.getBlock(x, y, z); world.markAndNotifyBlock(x, y, z, null, oldBlock, newBlock, flag); } world.capturedBlockSnapshots.clear(); return true; } else { world.capturedBlockSnapshots.clear(); return false; } }
@Override public boolean generateTree(Location location, TreeType type) { throw Pokkit.unsupported(); }
@Override public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) { throw Pokkit.unsupported(); }