mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-22 12:59:44 +00:00
Implement spawn tree and spawn forest commands
This commit is contained in:
1 parent
1b741eaac5
commit
a8b7098f39
14 files changed
+268
-126
No files matched your search
@@ -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());
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
||||
@@ -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() + " <player-name> <species-name>";
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
}
|
||||
@@ -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() + " <player-name> <species-name>";
|
||||
}
|
||||
|
||||
@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);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> addTabCompletionOptions(ICommandSender sender, String[] parameters) {
|
||||
if (parameters.length == 1) {
|
||||
List<String> 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<String> species = new ArrayList<String>();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Executable → Regular
+2
-2
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+1
-1
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user