Fix and migrate Tree commands to new format. Remove CommandMC

This commit is contained in:
mezz committed 2014-12-13 23:38:36 -08:00
1 parent a8b7098f39
commit a68cbc54e7
25 files changed
+621 -589

No files matched your search

@@ -0,0 +1,59 @@
/*******************************************************************************
* 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.apiculture.commands;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.world.World;
import forestry.api.apiculture.IBeekeepingMode;
import forestry.core.commands.ICommandModeHelper;
import forestry.plugins.PluginApiculture;
public class BeeModeHelper implements ICommandModeHelper {
@Override
public String[] getModeNames() {
ArrayList<IBeekeepingMode> beekeepingModes = PluginApiculture.beeInterface.getBeekeepingModes();
int modeStringCount = beekeepingModes.size();
List<String> modeStrings = new ArrayList<String>(modeStringCount);
for (IBeekeepingMode mode : beekeepingModes)
modeStrings.add(mode.getName());
return modeStrings.toArray(new String[modeStringCount]);
}
@Override
public String getModeNameMatching(String desired) {
IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(desired);
if (mode == null)
return null;
return mode.getName();
}
@Override
public String getModeName(World world) {
return PluginApiculture.beeInterface.getBeekeepingMode(world).getName();
}
@Override
public void setMode(World world, String modeName) {
PluginApiculture.beeInterface.setBeekeepingMode(world, modeName);
}
@Override
public ArrayList<String> getDescription(String modeName) {
IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(modeName);
return mode.getDescription();
}
}
@@ -0,0 +1,78 @@
/*******************************************************************************
* 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.apiculture.commands;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IApiaristTracker;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IBreedingTracker;
import forestry.core.commands.IStatsSaveHelper;
import forestry.core.utils.StringUtil;
import forestry.plugins.PluginApiculture;
import com.mojang.authlib.GameProfile;
public class BeeStatsSaveHelper implements IStatsSaveHelper {
@Override
public String getUnlocalizedSaveStatsString() {
return "for.chat.command.forestry.bee.save.stats";
}
@Override
public void addExtraInfo(Collection<String> statistics, IBreedingTracker breedingTracker) {
IApiaristTracker tracker = (IApiaristTracker)breedingTracker;
String discoveredLine = StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.discovered") + ":";
statistics.add(discoveredLine);
statistics.add(StringUtil.line(discoveredLine.length()));
String queen = StatCollector.translateToLocal("for.bees.grammar.queen.type");
String princess = StatCollector.translateToLocal("for.bees.grammar.princess.type");
String drone = StatCollector.translateToLocal("for.bees.grammar.drone.type");
statistics.add(queen + ":\t\t" + tracker.getQueenCount());
statistics.add(princess + ":\t" + tracker.getPrincessCount());
statistics.add(drone + ":\t\t" + tracker.getDroneCount());
statistics.add("");
}
@Override
public String getModeName(World world) {
return PluginApiculture.beeInterface.getBeekeepingMode(world).getName();
}
@Override
public Collection<IAlleleSpecies> getSpecies() {
Collection<IAlleleSpecies> species = new ArrayList<IAlleleSpecies>();
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values())
if (allele instanceof IAlleleBeeSpecies)
species.add((IAlleleBeeSpecies) allele);
return species;
}
@Override
public String getFileSuffix() {
return "bees";
}
@Override
public IBreedingTracker getBreedingTracker(World world, GameProfile gameProfile) {
return PluginApiculture.beeInterface.getBreedingTracker(world, gameProfile);
}
}
@@ -0,0 +1,32 @@
/*******************************************************************************
* 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.apiculture.commands;
import forestry.core.commands.CommandMode;
import forestry.core.commands.CommandSaveStats;
import forestry.core.commands.ICommandModeHelper;
import forestry.core.commands.IStatsSaveHelper;
import forestry.core.commands.SubCommand;
public class CommandBee extends SubCommand {
public CommandBee() {
super("bee");
addAlias("beekeeping");
IStatsSaveHelper saveHelper = new BeeStatsSaveHelper();
ICommandModeHelper modeHelper = new BeeModeHelper();
addChildCommand(new CommandMode(modeHelper));
addChildCommand(new CommandSaveStats(saveHelper));
addChildCommand(new CommandBeeGive());
}
}
@@ -30,12 +30,12 @@ import forestry.core.commands.SubCommand;
import forestry.core.commands.TemplateNotFoundException;
import forestry.plugins.PluginApiculture;
public class CommandBeekeepingGiveBee extends SubCommand {
public class CommandBeeGive extends SubCommand {
private final String beeTypeHelpString;
private final String[] beeTypeArr;
public CommandBeekeepingGiveBee() {
public CommandBeeGive() {
super("give");
setPermLevel(PermLevel.ADMIN);
@@ -93,7 +93,7 @@ public class CommandBeekeepingGiveBee extends SubCommand {
ItemStack beeStack = PluginApiculture.beeInterface.getMemberStack(bee, beeType.ordinal());
player.dropPlayerItemWithRandomChoice(beeStack, true);
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.give.given", player.getCommandSenderName(), bee.getGenome().getPrimary().getName(), beeType.getName());
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.bee.give.given", player.getCommandSenderName(), bee.getGenome().getPrimary().getName(), beeType.getName());
}
private static IBeeGenome getBeeGenome(String speciesName) {
@@ -1,247 +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 java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import net.minecraft.command.CommandException;
import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import com.mojang.authlib.GameProfile;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.arboriculture.IArboristTracker;
import forestry.api.arboriculture.ITreekeepingMode;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.core.config.Defaults;
import forestry.core.config.Version;
import forestry.core.proxy.Proxies;
import forestry.core.utils.CommandMC;
import forestry.core.utils.StringUtil;
import forestry.plugins.PluginArboriculture;
public class CommandTreekeepingMode extends CommandMC {
private final String[] modeStrings;
public CommandTreekeepingMode() {
modeStrings = new String[PluginArboriculture.treeInterface.getTreekeepingModes().size()];
for (int i = 0; i < PluginArboriculture.treeInterface.getTreekeepingModes().size(); i++)
modeStrings[i] = PluginArboriculture.treeInterface.getTreekeepingModes().get(i).getName();
}
@Override
public int compareTo(Object arg0) {
return this.getCommandName().compareTo(((ICommand) arg0).getCommandName());
}
@Override
public String getCommandName() {
return "treekeeping";
}
@Override
public String getCommandUsage(ICommandSender var1) {
return "/" + this.getCommandName() + " help";
}
@SuppressWarnings("rawtypes")
@Override
public List getCommandAliases() {
return null;
}
@Override
public void processCommand(ICommandSender sender, String[] arguments) {
if (arguments.length <= 0)
throw new WrongUsageException(StringUtil.localizeAndFormat("chat.help", this.getCommandUsage(sender)));
if (arguments[0].matches("list"))
listModes(sender, arguments);
else if (arguments[0].matches("info"))
listModeInfo(sender, arguments);
else if (arguments[0].matches("set")) {
if (arguments.length <= 1)
throw new WrongUsageException("/" + this.getCommandName() + " set [<world-#>] <mode-name>");
World world = getWorld(sender, arguments);
String desired = arguments[arguments.length - 1];
ITreekeepingMode mode = PluginArboriculture.treeInterface.getTreekeepingMode(desired);
if (mode == null)
throw new CommandException(StringUtil.localize("chat.trees.command.treekeeping.error"), desired);
PluginArboriculture.treeInterface.setTreekeepingMode(world, mode.getName());
func_152373_a(sender, this, StringUtil.localize("chat.trees.command.treekeeping.set"), mode.getName());
} else if (arguments[0].matches("save")) {
if (arguments.length <= 1)
throw new WrongUsageException("/" + this.getCommandName() + " save <player-name>");
saveStatistics(sender, arguments);
} else if (arguments[0].matches("help")) {
sendChatMessage(sender, StringUtil.localizeAndFormat("chat.trees.command.help.0", this.getCommandName()));
sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.1"));
sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.2"));
sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.3"));
sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.4"));
sendChatMessage(sender, StringUtil.localize("chat.trees.command.help.5"));
}
}
private void saveStatistics(ICommandSender sender, String[] arguments) {
String newLine = System.getProperty("line.separator");
World world = getWorld(sender, arguments);
String player = arguments[1];
Collection<String> statistics = new ArrayList<String>();
statistics.add(String.format("Treekeeping statistics for %s on %s:", player, DateFormat.getInstance().format(new Date())));
statistics.add("");
statistics.add("MODE: " + PluginArboriculture.treeInterface.getTreekeepingMode(world).getName());
statistics.add("");
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(player);
IArboristTracker tracker = PluginArboriculture.treeInterface.getBreedingTracker(world, profile);
if (tracker == null)
statistics.add("No statistics found.");
else {
statistics.add("BRED:");
statistics.add("-----");
statistics.add("");
Collection<IAlleleTreeSpecies> species = new ArrayList<IAlleleTreeSpecies>();
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values())
if (allele instanceof IAlleleTreeSpecies)
species.add((IAlleleTreeSpecies) allele);
statistics.add(String.format("SPECIES (%s):", species.size()));
statistics.add("-------------");
statistics.add("");
for (IAlleleTreeSpecies allele : species)
statistics.add(generateSpeciesListEntry(allele, tracker));
}
File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player + ".log");
try {
if (file.getParentFile() != null)
file.getParentFile().mkdirs();
if (!file.exists() && !file.createNewFile()) {
sendChatMessage(sender, "Log file could not be created. Failed to save statistics.");
return;
}
if (!file.canWrite()) {
sendChatMessage(sender, "Cannot write to log file. Failed to save statistics.");
return;
}
FileOutputStream fileout = new FileOutputStream(file);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(fileout, "UTF-8"));
writer.write("# " + Defaults.MOD + newLine + "# " + Version.getVersion() + newLine);
for (String line : statistics)
writer.write(line + newLine);
writer.close();
} catch (Exception ex) {
sendChatMessage(sender, "Write operation threw an exception. Failed to save statistics.");
ex.printStackTrace();
}
sendChatMessage(sender, "Saved statistics for player " + player);
}
private String generateSpeciesListEntry(IAlleleTreeSpecies species, IArboristTracker tracker) {
String discovered = "[ ]";
if (tracker.isDiscovered(species))
discovered = "[ X ]";
String blacklisted = "[ ]";
if (AlleleManager.alleleRegistry.isBlacklisted(species.getUID()))
blacklisted = "[ BL ]";
String notcounted = "[ ]";
if (!species.isCounted())
notcounted = "[ NC ]";
return String.format("%s %s %s\t%-40s %-20s %-20s", discovered, blacklisted, notcounted, species.getUID(), species.getName(), species.getAuthority());
}
private void listModes(ICommandSender sender, String[] arguments) {
World world = getWorld(sender, arguments);
sendChatMessage(sender, "Current: " + PluginArboriculture.treeInterface.getTreekeepingMode(world).getName() + " (#" + world.getWorldInfo().getSaveVersion()
+ ")");
String help = "";
for (ITreekeepingMode mode : PluginArboriculture.treeInterface.getTreekeepingModes()) {
if (!help.isEmpty())
help += ", ";
help += mode.getName();
}
sendChatMessage(sender, "Available modes: " + help);
}
private void listModeInfo(ICommandSender sender, String[] arguments) {
if (arguments.length <= 1)
throw new WrongUsageException("/" + this.getCommandName() + " info <mode-name>");
ITreekeepingMode found = null;
for (ITreekeepingMode mode : PluginArboriculture.treeInterface.getTreekeepingModes())
if (mode.getName().equalsIgnoreCase(arguments[1])) {
found = mode;
break;
}
if (found == null)
throw new CommandException("No treekeeping mode called '%s' is available.", arguments[1]);
sendChatMessage(sender, "\u00A7aMode: " + found.getName());
for (String desc : found.getDescription())
sendChatMessage(sender, StringUtil.localize(desc));
}
@Override
public boolean canCommandSenderUseCommand(ICommandSender sender) {
if (sender instanceof EntityPlayer)
return Proxies.common.isOp((EntityPlayer) sender);
else
return sender.canCommandSenderUseCommand(4, getCommandName());
}
@SuppressWarnings("rawtypes")
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] incomplete) {
return getListOfStringsMatchingLastWord(incomplete, modeStrings);
}
}
@@ -0,0 +1,33 @@
/*******************************************************************************
* 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.CommandMode;
import forestry.core.commands.CommandSaveStats;
import forestry.core.commands.ICommandModeHelper;
import forestry.core.commands.IStatsSaveHelper;
import forestry.core.commands.SubCommand;
public class CommandTree extends SubCommand {
public CommandTree() {
super("tree");
IStatsSaveHelper saveHelper = new TreeStatsSaveHelper();
ICommandModeHelper modeHelper = new TreeModeHelper();
addChildCommand(new CommandTreeSpawn("spawnTree", new TreeSpawner()));
addChildCommand(new CommandTreeSpawn("spawnForest", new ForestSpawner()));
addChildCommand(new CommandMode(modeHelper));
addChildCommand(new CommandSaveStats(saveHelper));
}
}
@@ -16,27 +16,23 @@ 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 final class CommandTreeSpawn extends SubCommand {
public CommandTreesSpawn(String name) {
private final ITreeSpawner treeSpawner;
public CommandTreeSpawn(String name, ITreeSpawner treeSpawner) {
super(name);
setPermLevel(PermLevel.ADMIN);
this.treeSpawner = treeSpawner;
}
@Override
@@ -58,27 +54,9 @@ public abstract class CommandTreesSpawn extends SubCommand {
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);
}
boolean success = treeSpawner.spawn(sender, treeName, player);
if (!success)
printHelp(sender);
}
@Override
@@ -103,39 +81,4 @@ public abstract class CommandTreesSpawn extends SubCommand {
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);
}
}
@@ -1,31 +0,0 @@
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);
}
}
@@ -15,13 +15,9 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.Vec3;
import net.minecraft.world.gen.feature.WorldGenerator;
public class CommandTreesSpawnForest extends CommandTreesSpawn {
public class ForestSpawner implements ITreeSpawner {
public CommandTreesSpawnForest() {
super("spawnForest");
}
protected void processSubCommand(ICommandSender sender, String treeName, EntityPlayer player) {
public boolean spawn(ICommandSender sender, String treeName, EntityPlayer player) {
Vec3 look = player.getLookVec();
int x = (int)Math.round(player.posX + (16 * look.xCoord));
@@ -32,13 +28,13 @@ public class CommandTreesSpawnForest extends CommandTreesSpawn {
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);
WorldGenerator gen = TreeGenHelper.getWorldGen(treeName, player, spawnX, y, spawnZ);
if (gen == null) {
printHelp(sender);
return;
return false;
}
generateTree(gen, player, spawnX, y, spawnZ);
TreeGenHelper.generateTree(gen, player, spawnX, y, spawnZ);
}
return true;
}
}
@@ -10,14 +10,11 @@
******************************************************************************/
package forestry.arboriculture.commands;
import forestry.core.commands.SubCommand;
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayer;
public class CommandTrees extends SubCommand {
public interface ITreeSpawner {
public CommandTrees() {
super("tree");
addChildCommand(new CommandTreesSpawnTree());
addChildCommand(new CommandTreesSpawnForest());
}
boolean spawn(ICommandSender sender, String treeName, EntityPlayer player);
}
@@ -0,0 +1,80 @@
/*******************************************************************************
* 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.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.SpeciesNotFoundException;
import forestry.core.commands.TemplateNotFoundException;
import forestry.core.worldgen.WorldGenBase;
import forestry.plugins.PluginArboriculture;
public final class TreeGenHelper {
public static 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);
}
public static 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);
}
}
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,59 @@
/*******************************************************************************
* 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.world.World;
import forestry.api.arboriculture.ITreekeepingMode;
import forestry.core.commands.ICommandModeHelper;
import forestry.plugins.PluginArboriculture;
public class TreeModeHelper implements ICommandModeHelper {
@Override
public String[] getModeNames() {
ArrayList<ITreekeepingMode> treekeepingModes = PluginArboriculture.treeInterface.getTreekeepingModes();
int modeStringCount = treekeepingModes.size();
List<String> modeStrings = new ArrayList<String>(modeStringCount);
for (ITreekeepingMode mode : treekeepingModes)
modeStrings.add(mode.getName());
return modeStrings.toArray(new String[modeStringCount]);
}
@Override
public String getModeNameMatching(String desired) {
ITreekeepingMode mode = PluginArboriculture.treeInterface.getTreekeepingMode(desired);
if (mode == null)
return null;
return mode.getName();
}
@Override
public String getModeName(World world) {
return PluginArboriculture.treeInterface.getTreekeepingMode(world).getName();
}
@Override
public void setMode(World world, String modeName) {
PluginArboriculture.treeInterface.setTreekeepingMode(world, modeName);
}
@Override
public ArrayList<String> getDescription(String modeName) {
ITreekeepingMode mode = PluginArboriculture.treeInterface.getTreekeepingMode(modeName);
return mode.getDescription();
}
}
@@ -0,0 +1,37 @@
/*******************************************************************************
* 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 TreeSpawner implements ITreeSpawner {
@Override
public boolean spawn(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 = TreeGenHelper.getWorldGen(treeName, player, x, y, z);
if (gen == null) {
return false;
}
TreeGenHelper.generateTree(gen, player, x, y, z);
return true;
}
}
@@ -0,0 +1,63 @@
/*******************************************************************************
* 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.Collection;
import net.minecraft.world.World;
import forestry.api.arboriculture.IAlleleTreeSpecies;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IBreedingTracker;
import forestry.core.commands.IStatsSaveHelper;
import forestry.plugins.PluginArboriculture;
import com.mojang.authlib.GameProfile;
public class TreeStatsSaveHelper implements IStatsSaveHelper {
@Override
public String getUnlocalizedSaveStatsString() {
return "for.chat.command.forestry.tree.save.stats";
}
@Override
public void addExtraInfo(Collection<String> statistics, IBreedingTracker breedingTracker) {
}
@Override
public String getModeName(World world) {
return PluginArboriculture.treeInterface.getTreekeepingMode(world).getName();
}
@Override
public Collection<IAlleleSpecies> getSpecies() {
Collection<IAlleleSpecies> species = new ArrayList<IAlleleSpecies>();
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values())
if (allele instanceof IAlleleTreeSpecies)
species.add((IAlleleTreeSpecies) allele);
return species;
}
@Override
public String getFileSuffix() {
return "trees";
}
@Override
public IBreedingTracker getBreedingTracker(World world, GameProfile gameProfile) {
return PluginArboriculture.treeInterface.getBreedingTracker(world, gameProfile);
}
}
@@ -4,19 +4,17 @@
* 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.apiculture.commands;
package forestry.core.commands;
import forestry.core.commands.SubCommand;
public class CommandMode extends SubCommand {
public class CommandBeekeepingMode extends SubCommand {
public CommandBeekeepingMode() {
public CommandMode(ICommandModeHelper modeHelper) {
super("mode");
addChildCommand(new CommandBeekeepingModeInfo());
addChildCommand(new CommandBeekeepingModeSet());
addChildCommand(new CommandModeInfo(modeHelper));
addChildCommand(new CommandModeSet(modeHelper));
}
}
@@ -8,45 +8,28 @@
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.commands;
package forestry.core.commands;
import java.util.List;
import forestry.api.apiculture.IBeekeepingMode;
import forestry.core.commands.CommandHelpers;
import forestry.core.commands.SubCommand;
import forestry.plugins.PluginApiculture;
import net.minecraft.command.ICommandSender;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class CommandBeekeepingModeInfo extends SubCommand {
import org.apache.commons.lang3.StringUtils;
public class CommandModeInfo extends SubCommand {
private final String[] modeStringArr;
private final String helpString;
private final ICommandModeHelper modeHelper;
public CommandBeekeepingModeInfo() {
public CommandModeInfo(ICommandModeHelper modeHelper) {
super("info");
List<String> modeStrings = new ArrayList<String>();
for (IBeekeepingMode mode : PluginApiculture.beeInterface.getBeekeepingModes())
modeStrings.add(mode.getName());
modeStringArr = modeStrings.toArray(new String[modeStrings.size()]);
StringBuilder help = new StringBuilder();
String separator = ", ";
Iterator<String> iter = modeStrings.iterator();
while (iter.hasNext()) {
help.append(iter.next());
if (iter.hasNext())
help.append(separator);
}
helpString = help.toString();
this.modeHelper = modeHelper;
modeStringArr = modeHelper.getModeNames();
helpString = StringUtils.join(modeStringArr, ", ");
}
@Override
@@ -56,42 +39,33 @@ public class CommandBeekeepingModeInfo extends SubCommand {
return;
}
String modeName = args[0];
String modeName = modeHelper.getModeNameMatching(args[0]);
IBeekeepingMode found = findModeWithName(modeName);
if (found == null) {
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.info.error", modeName);
if (modeName == null) {
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.info.error", args[0]);
printHelp(sender);
return;
}
ChatStyle green = new ChatStyle();
green.setColor(EnumChatFormatting.GREEN);
CommandHelpers.sendLocalizedChatMessage(sender, green, found.getName());
CommandHelpers.sendLocalizedChatMessage(sender, green, modeName);
for (String desc : found.getDescription())
for (String desc : modeHelper.getDescription(modeName))
CommandHelpers.sendLocalizedChatMessage(sender, "for." + desc);
}
private IBeekeepingMode findModeWithName(String name) {
for (IBeekeepingMode mode : PluginApiculture.beeInterface.getBeekeepingModes()) {
if (mode.getName().equalsIgnoreCase(name))
return mode;
}
return null;
}
@Override
public void printHelp(ICommandSender sender) {
super.printHelp(sender);
World world = CommandHelpers.getWorld(sender, this);
String modeName = PluginApiculture.beeInterface.getBeekeepingMode(world).getName();
String modeName = modeHelper.getModeName(world);
String worldName = String.valueOf(world.getWorldInfo().getSaveVersion());
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.info.current", modeName, worldName);
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.info.available", helpString);
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.info.current", modeName, worldName);
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.info.available", helpString);
}
@Override
@@ -8,30 +8,24 @@
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.commands;
package forestry.core.commands;
import java.util.List;
import forestry.api.apiculture.IBeekeepingMode;
import forestry.core.commands.CommandHelpers;
import forestry.core.commands.SubCommand;
import forestry.plugins.PluginApiculture;
import net.minecraft.command.ICommandSender;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.List;
public class CommandBeekeepingModeSet extends SubCommand {
public final class CommandModeSet extends SubCommand {
private final String[] modeStringArr;
private final ICommandModeHelper modeSetter;
public CommandBeekeepingModeSet() {
public CommandModeSet(ICommandModeHelper modeSetter) {
super("set");
setPermLevel(PermLevel.ADMIN);
int modeStringCount = PluginApiculture.beeInterface.getBeekeepingModes().size();
List<String> modeStrings = new ArrayList<String>(modeStringCount);
for (IBeekeepingMode mode : PluginApiculture.beeInterface.getBeekeepingModes())
modeStrings.add(mode.getName());
modeStringArr = modeStrings.toArray(new String[modeStringCount]);
this.modeSetter = modeSetter;
modeStringArr = modeSetter.getModeNames();
}
@Override
@@ -49,15 +43,15 @@ public class CommandBeekeepingModeSet extends SubCommand {
String desired = args[args.length - 1];
IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(desired);
if (mode == null) {
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.set.error", desired);
String modeName = modeSetter.getModeNameMatching(desired);
if (modeName == null) {
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.set.error", desired);
printHelp(sender);
return;
}
PluginApiculture.beeInterface.setBeekeepingMode(world, mode.getName());
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.mode.set.success", mode.getName());
modeSetter.setMode(world, modeName);
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.mode.set.success", modeName);
}
@Override
@@ -8,23 +8,7 @@
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.commands;
import com.mojang.authlib.GameProfile;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IApiaristTracker;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.core.commands.CommandHelpers;
import forestry.core.commands.SubCommand;
import forestry.core.config.Defaults;
import forestry.core.config.Version;
import forestry.core.proxy.Proxies;
import forestry.plugins.PluginApiculture;
import net.minecraft.command.ICommandSender;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
package forestry.core.commands;
import java.io.BufferedWriter;
import java.io.File;
@@ -38,17 +22,32 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
public class CommandBeekeepingSave extends SubCommand {
import net.minecraft.command.ICommandSender;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IBreedingTracker;
import forestry.core.config.Defaults;
import forestry.core.config.Version;
import forestry.core.proxy.Proxies;
import forestry.core.utils.StringUtil;
public final class CommandSaveStats extends SubCommand {
private final String discoveredSymbol;
private final String blacklistedSymbol;
private final String notCountedSymbol;
private final IStatsSaveHelper saveHelper;
public CommandBeekeepingSave() {
public CommandSaveStats(IStatsSaveHelper saveHelper) {
super("save");
discoveredSymbol = StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.discovered.symbol");
blacklistedSymbol = StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.blacklisted.symbol");
notCountedSymbol = StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.notCounted.symbol");
discoveredSymbol = StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.discovered.symbol");
blacklistedSymbol = StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.blacklisted.symbol");
notCountedSymbol = StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.notCounted.symbol");
this.saveHelper = saveHelper;
}
@Override
@@ -58,7 +57,7 @@ public class CommandBeekeepingSave extends SubCommand {
@Override
public void processSubCommand(ICommandSender sender, String[] args) {
if (args.length != 1) {
if (args.length > 1) {
printHelp(sender);
return;
}
@@ -66,76 +65,66 @@ public class CommandBeekeepingSave extends SubCommand {
String newLine = System.getProperty("line.separator");
World world = CommandHelpers.getWorld(sender, this);
String player = args[0];
EntityPlayerMP player;
if (args.length > 0)
player = CommandHelpers.getPlayer(sender, args[0]);
else
player = CommandHelpers.getPlayer(sender, sender.getCommandSenderName());
Collection<String> statistics = new ArrayList<String>();
String date = DateFormat.getInstance().format(new Date());
statistics.add(StatCollector.translateToLocalFormatted("for.chat.command.forestry.beekeeping.save.stats", player, date));
statistics.add(StatCollector.translateToLocalFormatted(saveHelper.getUnlocalizedSaveStatsString(), player.getDisplayName(), date));
statistics.add("");
String modeName = PluginApiculture.beeInterface.getBeekeepingMode(world).getName();
statistics.add(StatCollector.translateToLocalFormatted("for.chat.command.forestry.beekeeping.save.mode", modeName));
statistics.add(StatCollector.translateToLocalFormatted("for.chat.command.forestry.stats.save.mode", saveHelper.getModeName(world)));
statistics.add("");
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(player);
IApiaristTracker tracker = PluginApiculture.beeInterface.getBreedingTracker(world, profile);
IBreedingTracker tracker = saveHelper.getBreedingTracker(world, player.getGameProfile());
if (tracker == null)
statistics.add(StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.error4"));
statistics.add(StatCollector.translateToLocal("for.chat.command.forestry.stats.save.error4"));
else {
String discoveredLine = StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.discovered") + ":";
statistics.add(discoveredLine);
statistics.add(line(discoveredLine.length()));
saveHelper.addExtraInfo(statistics, tracker);
String queen = StatCollector.translateToLocal("for.bees.grammar.queen.type");
String princess = StatCollector.translateToLocal("for.bees.grammar.princess.type");
String drone = StatCollector.translateToLocal("for.bees.grammar.drone.type");
statistics.add(queen + ":\t\t" + tracker.getQueenCount());
statistics.add(princess + ":\t" + tracker.getPrincessCount());
statistics.add(drone + ":\t\t" + tracker.getDroneCount());
statistics.add("");
Collection<IAlleleBeeSpecies> species = new ArrayList<IAlleleBeeSpecies>();
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values())
if (allele instanceof IAlleleBeeSpecies)
species.add((IAlleleBeeSpecies) allele);
Collection<IAlleleSpecies> species = saveHelper.getSpecies();
String speciesCount = StatCollector.translateToLocal("for.gui.speciescount");
String speciesCountLine = String.format("%s (%s):", speciesCount, species.size());
statistics.add(speciesCountLine);
statistics.add(line(speciesCountLine.length()));
statistics.add(StringUtil.line(speciesCountLine.length()));
statistics.add(discoveredSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.discovered"));
statistics.add(blacklistedSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.blacklisted"));
statistics.add(notCountedSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.beekeeping.save.key.notCounted"));
statistics.add(discoveredSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.discovered"));
statistics.add(blacklistedSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.blacklisted"));
statistics.add(notCountedSymbol + ": " + StatCollector.translateToLocal("for.chat.command.forestry.stats.save.key.notCounted"));
statistics.add("");
String header = generateSpeciesListHeader();
statistics.add(header);
statistics.add(line(header.length()));
statistics.add(StringUtil.line(header.length()));
statistics.add("");
for (IAlleleBeeSpecies allele : species)
for (IAlleleSpecies allele : species)
statistics.add(generateSpeciesListEntry(allele, tracker));
}
File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player + ".log");
File file = new File(Proxies.common.getForestryRoot(), "config/" + Defaults.MOD.toLowerCase(Locale.ENGLISH) + "/stats/" + player.getDisplayName() + "-" + saveHelper.getFileSuffix() + ".log");
try {
File folder = file.getParentFile();
if (folder != null && !folder.exists()) {
boolean success = file.getParentFile().mkdirs();
if (!success) {
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.error1");
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error1");
return;
}
}
if (!file.exists() && !file.createNewFile()) {
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.error1");
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error1");
return;
}
if (!file.canWrite()) {
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.error2");
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error2");
return;
}
@@ -151,20 +140,12 @@ public class CommandBeekeepingSave extends SubCommand {
}
catch (IOException ex) {
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.error3");
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.error3");
ex.printStackTrace();
return;
}
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.beekeeping.save.saved", player);
}
private String line(int length) {
StringBuilder line = new StringBuilder();
for (int i = 0; i < length; i++)
line.append("-");
return line.toString();
CommandHelpers.sendLocalizedChatMessage(sender, "for.chat.command.forestry.stats.save.saved", player.getDisplayName());
}
private String generateSpeciesListHeader() {
@@ -173,7 +154,7 @@ public class CommandBeekeepingSave extends SubCommand {
return speciesListEntry(discoveredSymbol, blacklistedSymbol, notCountedSymbol, "UID", species, authority);
}
private String generateSpeciesListEntry(IAlleleBeeSpecies species, IApiaristTracker tracker) {
private String generateSpeciesListEntry(IAlleleSpecies species, IBreedingTracker tracker) {
String discovered = "";
if (tracker.isDiscovered(species))
discovered = discoveredSymbol;
@@ -8,17 +8,19 @@
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.apiculture.commands;
package forestry.core.commands;
import forestry.core.commands.SubCommand;
import java.util.ArrayList;
public class CommandBeekeeping extends SubCommand {
import net.minecraft.world.World;
public CommandBeekeeping() {
super("bee");
addAlias("beekeeping");
addChildCommand(new CommandBeekeepingMode());
addChildCommand(new CommandBeekeepingSave());
addChildCommand(new CommandBeekeepingGiveBee());
}
public interface ICommandModeHelper {
String[] getModeNames();
String getModeNameMatching(String desired);
String getModeName(World world);
void setMode(World world, String modeName);
ArrayList<String> getDescription(String modeName);
}
@@ -0,0 +1,35 @@
/*******************************************************************************
* 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.core.commands;
import java.util.Collection;
import net.minecraft.world.World;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IBreedingTracker;
import com.mojang.authlib.GameProfile;
public interface IStatsSaveHelper {
String getUnlocalizedSaveStatsString();
void addExtraInfo(Collection<String> statistics, IBreedingTracker breedingTracker);
String getModeName(World world);
Collection<IAlleleSpecies> getSpecies();
String getFileSuffix();
IBreedingTracker getBreedingTracker(World world, GameProfile gameProfile);
}
@@ -1,53 +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.core.utils;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.ChatComponentText;
import net.minecraft.world.World;
@Deprecated
public abstract class CommandMC extends CommandBase {
protected World getWorld(ICommandSender sender, String[] arguments) {
// Handle passed in world argument
if (arguments.length > 2) {
int dim = 0;
try {
dim = Integer.parseInt(arguments[1]);
} catch (Exception ex) {
throw new WrongUsageException("/" + getCommandName() + " set [<world-#>] <beekeeping-mode>");
}
return MinecraftServer.getServer().worldServerForDimension(dim);
}
if (sender instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer) sender;
return player.worldObj;
} else
return MinecraftServer.getServer().worldServerForDimension(0);
}
protected String[] getPlayers() {
return MinecraftServer.getServer().getAllUsernames();
}
protected void sendChatMessage(ICommandSender sender, String message) {
sender.addChatMessage(new ChatComponentText(message));
}
}
@@ -89,4 +89,12 @@ public class StringUtil {
public static String floatAsPercent(float val) {
return (int) (val * 100) + " %";
}
public static String line(int length) {
StringBuilder line = new StringBuilder();
for (int i = 0; i < length; i++)
line.append("-");
return line.toString();
}
}
@@ -30,7 +30,6 @@ import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.common.BiomeDictionary;
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.FMLCommonHandler;
@@ -73,7 +72,7 @@ import forestry.apiculture.GuiHandlerApiculture;
import forestry.apiculture.PacketHandlerApiculture;
import forestry.apiculture.SaveEventHandlerApiculture;
import forestry.apiculture.VillageHandlerApiculture;
import forestry.apiculture.commands.CommandBeekeeping;
import forestry.apiculture.commands.CommandBee;
import forestry.apiculture.gadgets.BlockAlveary;
import forestry.apiculture.gadgets.BlockBeehives;
import forestry.apiculture.gadgets.BlockCandle;
@@ -269,8 +268,15 @@ public class PluginApiculture extends ForestryPlugin {
// Register village components with the Structure registry.
VillageHandlerApiculture.registerVillageComponents();
// Modes
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.easy);
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.normal);
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.hard);
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.hardcore);
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.insane);
// Commands
PluginCore.rootCommand.addChildCommand(new CommandBeekeeping());
PluginCore.rootCommand.addChildCommand(new CommandBee());
}
@Override
@@ -306,12 +312,6 @@ public class PluginApiculture extends ForestryPlugin {
createMutations();
registerBeehiveDrops();
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.easy);
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.normal);
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.hard);
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.hardcore);
PluginApiculture.beeInterface.registerBeekeepingMode(BeekeepingMode.insane);
// Inducers for swarmer
BeeManager.inducers.put(ForestryItem.royalJelly.getItemStack(), 10);
@@ -16,7 +16,6 @@ import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.command.ICommand;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
@@ -46,7 +45,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.CommandTreekeepingMode;
import forestry.arboriculture.EventHandlerArboriculture;
import forestry.arboriculture.FruitProviderNone;
import forestry.arboriculture.FruitProviderPod;
@@ -57,7 +55,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.commands.CommandTree;
import forestry.arboriculture.gadgets.BlockArbFence;
import forestry.arboriculture.gadgets.BlockArbFence.FenceCat;
import forestry.arboriculture.gadgets.BlockArbStairs;
@@ -295,8 +293,15 @@ public class PluginArboriculture extends ForestryPlugin {
validFences.add(Blocks.fence_gate);
validFences.add(Blocks.nether_brick_fence);
// Modes
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.easy);
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.normal);
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.hard);
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.hardcore);
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.insane);
// Commands
PluginCore.rootCommand.addChildCommand(new CommandTrees());
PluginCore.rootCommand.addChildCommand(new CommandTree());
}
@Override
@@ -313,12 +318,6 @@ public class PluginArboriculture extends ForestryPlugin {
registerTemplates();
registerErsatzGenomes();
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.easy);
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.normal);
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.hard);
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.hardcore);
PluginArboriculture.treeInterface.registerTreekeepingMode(TreekeepingMode.insane);
MinecraftForge.EVENT_BUS.register(new EventHandlerArboriculture());
VillagerRegistry.instance().registerVillagerId(Defaults.ID_VILLAGER_LUMBERJACK);
@@ -1102,11 +1101,6 @@ public class PluginArboriculture extends ForestryPlugin {
return new GuiHandlerArboriculture();
}
@Override
public ICommand[] getConsoleCommands() {
return new ICommand[]{new CommandTreekeepingMode()};
}
@Override
public IFuelHandler getFuelHandler() {
return new IFuelHandler() {