diff --git a/lang b/lang index 78a42965d..76846d9c7 160000 --- a/lang +++ b/lang @@ -1 +1 @@ -Subproject commit 78a42965de89d39804cccdaeed51ac2cf98f2919 +Subproject commit 76846d9c7646a02c8ac28e673579f065d499b3b9 diff --git a/src/main/java/forestry/apiculture/commands/CommandBeekeeping.java b/src/main/java/forestry/apiculture/commands/CommandBeekeeping.java index f39dccc23..ceeb66d33 100644 --- a/src/main/java/forestry/apiculture/commands/CommandBeekeeping.java +++ b/src/main/java/forestry/apiculture/commands/CommandBeekeeping.java @@ -15,8 +15,8 @@ import forestry.core.commands.SubCommand; public class CommandBeekeeping extends SubCommand { public CommandBeekeeping() { - super("beekeeping"); - addAlias("bee"); + super("bee"); + addAlias("beekeeping"); addChildCommand(new CommandBeekeepingMode()); addChildCommand(new CommandBeekeepingSave()); addChildCommand(new CommandBeekeepingGiveBee()); diff --git a/src/main/java/forestry/apiculture/commands/CommandBeekeepingGiveBee.java b/src/main/java/forestry/apiculture/commands/CommandBeekeepingGiveBee.java index b82f4d9b5..4134d27ca 100644 --- a/src/main/java/forestry/apiculture/commands/CommandBeekeepingGiveBee.java +++ b/src/main/java/forestry/apiculture/commands/CommandBeekeepingGiveBee.java @@ -10,24 +10,25 @@ ******************************************************************************/ package forestry.apiculture.commands; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + import forestry.api.apiculture.EnumBeeType; import forestry.api.apiculture.IAlleleBeeSpecies; import forestry.api.apiculture.IBee; import forestry.api.apiculture.IBeeGenome; import forestry.api.genetics.AlleleManager; import forestry.api.genetics.IAllele; -import forestry.apiculture.SpeciesNotFoundException; -import forestry.apiculture.TemplateNotFoundException; import forestry.core.commands.CommandHelpers; +import forestry.core.commands.SpeciesNotFoundException; import forestry.core.commands.SubCommand; +import forestry.core.commands.TemplateNotFoundException; import forestry.plugins.PluginApiculture; -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; public class CommandBeekeepingGiveBee extends SubCommand { diff --git a/src/main/java/forestry/arboriculture/CommandSpawnForest.java b/src/main/java/forestry/arboriculture/CommandSpawnForest.java deleted file mode 100755 index 2cb959d0b..000000000 --- a/src/main/java/forestry/arboriculture/CommandSpawnForest.java +++ /dev/null @@ -1,49 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.gen.feature.WorldGenerator; - -import forestry.api.world.ITreeGenData; -import forestry.arboriculture.genetics.TreeTemplates; -import forestry.arboriculture.worldgen.WorldGenBalsa; -import forestry.core.utils.CommandMC; -import forestry.plugins.PluginArboriculture; - -public class CommandSpawnForest extends CommandMC { - - @Override - public String getCommandName() { - return "spawnforest"; - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "/" + getCommandName() + " "; - } - - @Override - public void processCommand(ICommandSender sender, String[] arguments) { - EntityPlayer player = getCommandSenderAsPlayer(sender); - - int x = (int) player.posX - 16; - int y = (int) (player.posY); - int z = (int) player.posZ - 16; - - WorldGenerator gen = new WorldGenBalsa((ITreeGenData) PluginArboriculture.treeInterface.getTree(player.worldObj, - TreeTemplates.templateAsGenome(PluginArboriculture.treeInterface.getTemplate("treeBalsa")))); - - for (int i = 0; i < 16; i++) - gen.generate(player.worldObj, player.worldObj.rand, x + player.worldObj.rand.nextInt(32), y, z + player.worldObj.rand.nextInt(32)); - } -} diff --git a/src/main/java/forestry/arboriculture/CommandSpawnTree.java b/src/main/java/forestry/arboriculture/CommandSpawnTree.java deleted file mode 100755 index 9ad8e744a..000000000 --- a/src/main/java/forestry/arboriculture/CommandSpawnTree.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011-2014 SirSengir. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Lesser Public License v3 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/lgpl-3.0.txt - * - * Various Contributors including, but not limited to: - * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges - ******************************************************************************/ -package forestry.arboriculture; - -import net.minecraft.command.ICommandSender; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.world.gen.feature.WorldGenerator; - -import forestry.api.world.ITreeGenData; -import forestry.arboriculture.genetics.TreeTemplates; -import forestry.arboriculture.worldgen.WorldGenBalsa; -import forestry.core.utils.CommandMC; -import forestry.plugins.PluginArboriculture; - -public class CommandSpawnTree extends CommandMC { - - public CommandSpawnTree() { - } - - @Override - public String getCommandName() { - return "spawntree"; - } - - @Override - public String getCommandUsage(ICommandSender sender) { - return "/" + getCommandName() + " "; - } - - @Override - public void processCommand(ICommandSender sender, String[] arguments) { - EntityPlayer player = getCommandSenderAsPlayer(sender); - - int x = (int) player.posX; - int y = (int) (player.posY); - int z = (int) player.posZ; - - WorldGenerator gen = new WorldGenBalsa((ITreeGenData) PluginArboriculture.treeInterface.getTree(player.worldObj, - TreeTemplates.templateAsGenome(PluginArboriculture.treeInterface.getTemplate("treeBalsa")))); - - gen.generate(player.worldObj, player.worldObj.rand, x, y, z); - - } -} diff --git a/src/main/java/forestry/arboriculture/commands/CommandTrees.java b/src/main/java/forestry/arboriculture/commands/CommandTrees.java new file mode 100644 index 000000000..dc6da946e --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/CommandTrees.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import forestry.core.commands.SubCommand; + +public class CommandTrees extends SubCommand { + + public CommandTrees() { + super("tree"); + addChildCommand(new CommandTreesSpawnTree()); + addChildCommand(new CommandTreesSpawnForest()); + } + +} diff --git a/src/main/java/forestry/arboriculture/commands/CommandTreesSpawn.java b/src/main/java/forestry/arboriculture/commands/CommandTreesSpawn.java new file mode 100644 index 000000000..7a05b7964 --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/CommandTreesSpawn.java @@ -0,0 +1,141 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.command.ICommandSender; +import net.minecraft.command.PlayerNotFoundException; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.gen.feature.WorldGenerator; + +import forestry.api.arboriculture.IAlleleTreeSpecies; +import forestry.api.arboriculture.ITree; +import forestry.api.arboriculture.ITreeGenome; +import forestry.api.genetics.AlleleManager; +import forestry.api.genetics.IAllele; +import forestry.core.commands.CommandHelpers; +import forestry.core.commands.SpeciesNotFoundException; +import forestry.core.commands.SubCommand; +import forestry.core.commands.TemplateNotFoundException; +import forestry.core.worldgen.WorldGenBase; +import forestry.plugins.PluginArboriculture; + +import org.apache.commons.lang3.StringUtils; + +public abstract class CommandTreesSpawn extends SubCommand { + + public CommandTreesSpawn(String name) { + super(name); + setPermLevel(PermLevel.ADMIN); + } + + @Override + public final void processSubCommand(ICommandSender sender, String[] arguments) { + if (arguments.length < 1 || arguments.length > 2) { + printHelp(sender); + return; + } + + EntityPlayer player; + String treeName; + try { + player = CommandHelpers.getPlayer(sender, arguments[arguments.length - 1]); + String[] argumentsWithoutPlayer = new String[arguments.length - 1]; + System.arraycopy(arguments, 0, argumentsWithoutPlayer, 0, arguments.length - 1); + treeName = StringUtils.join(argumentsWithoutPlayer, " "); + } catch (PlayerNotFoundException e) { + player = CommandHelpers.getPlayer(sender, sender.getCommandSenderName()); + treeName = StringUtils.join(arguments, " "); + } + + processSubCommand(sender, treeName, player); + } + + protected abstract void processSubCommand(ICommandSender sender, String treeName, EntityPlayer player); + + protected final WorldGenerator getWorldGen(String treeName, EntityPlayer player, int x, int y, int z) { + ITreeGenome treeGenome = getTreeGenome(treeName); + if (treeGenome == null) { + return null; + } + + ITree tree = PluginArboriculture.treeInterface.getTree(player.worldObj, treeGenome); + return tree.getTreeGenerator(player.worldObj, x, y, z, true); + } + + protected final void generateTree(WorldGenerator gen, EntityPlayer player, int x, int y, int z) { + if (gen instanceof WorldGenBase) { + ((WorldGenBase) gen).generate(player.worldObj, player.worldObj.rand, x, y, z, true); + } else { + gen.generate(player.worldObj, player.worldObj.rand, x, y, z); + } + } + + @Override + public List addTabCompletionOptions(ICommandSender sender, String[] parameters) { + if (parameters.length == 1) { + List tabCompletion = CommandHelpers.getListOfStringsMatchingLastWord(parameters, getSpecies()); + tabCompletion.add("help"); + return tabCompletion; + } else if (parameters.length == 2) { + return CommandHelpers.getListOfStringsMatchingLastWord(parameters, CommandHelpers.getPlayers()); + } + return null; + } + + private static String[] getSpecies() { + List species = new ArrayList(); + + for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) + if (allele instanceof IAlleleTreeSpecies) + species.add(allele.getName().replaceAll("\\s", "")); + + return species.toArray(new String[species.size()]); + } + + private static ITreeGenome getTreeGenome(String speciesName) { + IAlleleTreeSpecies species = null; + + for (String uid : AlleleManager.alleleRegistry.getRegisteredAlleles().keySet()) { + + if (!uid.equals(speciesName)) + continue; + + IAllele allele = AlleleManager.alleleRegistry.getAllele(uid); + if (allele instanceof IAlleleTreeSpecies) { + species = (IAlleleTreeSpecies) allele; + break; + } + } + + if (species == null) { + for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values()) { + if (allele instanceof IAlleleTreeSpecies && allele.getName().replaceAll("\\s", "").equals(speciesName)) { + species = (IAlleleTreeSpecies) allele; + break; + } + } + } + + if (species == null) + throw new SpeciesNotFoundException(speciesName); + + IAllele[] template = PluginArboriculture.treeInterface.getTemplate(species.getUID()); + + if (template == null) + throw new TemplateNotFoundException(species); + + return PluginArboriculture.treeInterface.templateAsGenome(template); + } + +} diff --git a/src/main/java/forestry/arboriculture/commands/CommandTreesSpawnForest.java b/src/main/java/forestry/arboriculture/commands/CommandTreesSpawnForest.java new file mode 100644 index 000000000..450b3956a --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/CommandTreesSpawnForest.java @@ -0,0 +1,44 @@ +/******************************************************************************* + * Copyright (c) 2011-2014 SirSengir. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser Public License v3 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl-3.0.txt + * + * Various Contributors including, but not limited to: + * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges + ******************************************************************************/ +package forestry.arboriculture.commands; + +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.gen.feature.WorldGenerator; + +public class CommandTreesSpawnForest extends CommandTreesSpawn { + + public CommandTreesSpawnForest() { + super("spawnForest"); + } + + protected void processSubCommand(ICommandSender sender, String treeName, EntityPlayer player) { + Vec3 look = player.getLookVec(); + + int x = (int)Math.round(player.posX + (16 * look.xCoord)); + int y = (int)Math.round(player.posY); + int z = (int)Math.round(player.posZ + (16 * look.zCoord)); + + for (int i = 0; i < 16; i++) { + int spawnX = x + player.worldObj.rand.nextInt(32) - 16; + int spawnZ = z + player.worldObj.rand.nextInt(32) - 16; + + WorldGenerator gen = getWorldGen(treeName, player, spawnX, y, spawnZ); + if (gen == null) { + printHelp(sender); + return; + } + generateTree(gen, player, spawnX, y, spawnZ); + } + } + +} diff --git a/src/main/java/forestry/arboriculture/commands/CommandTreesSpawnTree.java b/src/main/java/forestry/arboriculture/commands/CommandTreesSpawnTree.java new file mode 100644 index 000000000..54daa8061 --- /dev/null +++ b/src/main/java/forestry/arboriculture/commands/CommandTreesSpawnTree.java @@ -0,0 +1,31 @@ +package forestry.arboriculture.commands; + +import net.minecraft.command.ICommandSender; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.Vec3; +import net.minecraft.world.gen.feature.WorldGenerator; + +public class CommandTreesSpawnTree extends CommandTreesSpawn { + + public CommandTreesSpawnTree() { + super("spawnTree"); + } + + @Override + protected void processSubCommand(ICommandSender sender, String treeName, EntityPlayer player) { + Vec3 look = player.getLookVec(); + + int x = (int)Math.round(player.posX + (3 * look.xCoord)); + int y = (int)Math.round(player.posY); + int z = (int)Math.round(player.posZ + (3 * look.zCoord)); + + WorldGenerator gen = getWorldGen(treeName, player, x, y, z); + if (gen == null) { + printHelp(sender); + return; + } + + generateTree(gen, player, x, y, z); + } + +} diff --git a/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java b/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java index 8d4f87a4a..f93b72d7d 100755 --- a/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java +++ b/src/main/java/forestry/arboriculture/worldgen/WorldGenArboriculture.java @@ -43,7 +43,7 @@ public abstract class WorldGenArboriculture extends WorldGenBase { } @Override - public boolean subGenerate(int x, int y, int z) { + public boolean subGenerate(int x, int y, int z, boolean forced) { this.startX = x; this.startY = y; this.startZ = z; @@ -53,9 +53,9 @@ public abstract class WorldGenArboriculture extends WorldGenBase { this.wood = getWood(); preGenerate(); - if (!canGrow()) + if (!forced && !canGrow()) { return false; - else { + } else { generate(); return true; } diff --git a/src/main/java/forestry/apiculture/SpeciesNotFoundException.java b/src/main/java/forestry/core/commands/SpeciesNotFoundException.java old mode 100755 new mode 100644 similarity index 89% rename from src/main/java/forestry/apiculture/SpeciesNotFoundException.java rename to src/main/java/forestry/core/commands/SpeciesNotFoundException.java index 9e4308a12..c84501bf5 --- a/src/main/java/forestry/apiculture/SpeciesNotFoundException.java +++ b/src/main/java/forestry/core/commands/SpeciesNotFoundException.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.apiculture; +package forestry.core.commands; import net.minecraft.command.CommandException; @@ -17,7 +17,7 @@ public class SpeciesNotFoundException extends CommandException { private static final long serialVersionUID = 1L; public SpeciesNotFoundException(String title) { - super("Could not find bee species with Name or UID %s", title); + super("Could not find species with Name or UID %s", title); } } diff --git a/src/main/java/forestry/apiculture/TemplateNotFoundException.java b/src/main/java/forestry/core/commands/TemplateNotFoundException.java old mode 100755 new mode 100644 similarity index 96% rename from src/main/java/forestry/apiculture/TemplateNotFoundException.java rename to src/main/java/forestry/core/commands/TemplateNotFoundException.java index 16a157084..06da28fc5 --- a/src/main/java/forestry/apiculture/TemplateNotFoundException.java +++ b/src/main/java/forestry/core/commands/TemplateNotFoundException.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.apiculture; +package forestry.core.commands; import net.minecraft.command.CommandException; diff --git a/src/main/java/forestry/core/worldgen/WorldGenBase.java b/src/main/java/forestry/core/worldgen/WorldGenBase.java index 488863351..332e46770 100755 --- a/src/main/java/forestry/core/worldgen/WorldGenBase.java +++ b/src/main/java/forestry/core/worldgen/WorldGenBase.java @@ -42,15 +42,19 @@ public abstract class WorldGenBase extends WorldGenerator { @Override public final boolean generate(World world, Random random, int x, int y, int z) { + return generate(world, random, x, y, z, false); + } + + public final boolean generate(World world, Random random, int x, int y, int z, boolean forced) { this.world = world; this.rand = random; - boolean result = subGenerate(x, y, z); + boolean result = subGenerate(x, y, z, forced); this.world = null; this.rand = null; return result; } - public boolean subGenerate(int x, int y, int z) { + public boolean subGenerate(int x, int y, int z, boolean forced) { return false; } diff --git a/src/main/java/forestry/plugins/PluginArboriculture.java b/src/main/java/forestry/plugins/PluginArboriculture.java index 58b0f989c..304e55b37 100644 --- a/src/main/java/forestry/plugins/PluginArboriculture.java +++ b/src/main/java/forestry/plugins/PluginArboriculture.java @@ -25,7 +25,6 @@ import net.minecraft.util.WeightedRandomChestContent; import net.minecraftforge.common.ChestGenHooks; import net.minecraftforge.common.MinecraftForge; -import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.oredict.OreDictionary; import cpw.mods.fml.common.IFuelHandler; @@ -47,8 +46,6 @@ import forestry.api.genetics.IClassification.EnumClassLevel; import forestry.api.genetics.IFruitFamily; import forestry.api.recipes.RecipeManagers; import forestry.api.storage.BackpackManager; -import forestry.arboriculture.CommandSpawnForest; -import forestry.arboriculture.CommandSpawnTree; import forestry.arboriculture.CommandTreekeepingMode; import forestry.arboriculture.EventHandlerArboriculture; import forestry.arboriculture.FruitProviderNone; @@ -60,6 +57,7 @@ import forestry.arboriculture.GuiHandlerArboriculture; import forestry.arboriculture.PacketHandlerArboriculture; import forestry.arboriculture.VillageHandlerArboriculture; import forestry.arboriculture.WoodType; +import forestry.arboriculture.commands.CommandTrees; import forestry.arboriculture.gadgets.BlockArbFence; import forestry.arboriculture.gadgets.BlockArbFence.FenceCat; import forestry.arboriculture.gadgets.BlockArbStairs; @@ -297,6 +295,8 @@ public class PluginArboriculture extends ForestryPlugin { validFences.add(Blocks.fence_gate); validFences.add(Blocks.nether_brick_fence); + // Commands + PluginCore.rootCommand.addChildCommand(new CommandTrees()); } @Override @@ -1104,8 +1104,7 @@ public class PluginArboriculture extends ForestryPlugin { @Override public ICommand[] getConsoleCommands() { - return new ICommand[]{new CommandSpawnTree(), new CommandSpawnForest(), - new CommandTreekeepingMode()}; + return new ICommand[]{new CommandTreekeepingMode()}; } @Override