Reformed Forestry!

* Updated for BC 6.0.x compatibility
* Re-implemented the Pipes plugin
* Converted to vanilla assets lang system
* Converted to standard gradle file structure
* General warnings cleanup
This commit is contained in:
Parker committed 2014-08-11 16:56:09 -04:00
1 parent 36248c02f1
commit 8f2d802f11
1602 files changed
+724 -736

No files matched your search

+99
View File
@@ -0,0 +1,99 @@
/*******************************************************************************
* 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;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms.IMCEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import forestry.api.fuels.EngineBronzeFuel;
import forestry.api.fuels.EngineCopperFuel;
import forestry.api.fuels.FermenterFuel;
import forestry.api.fuels.FuelManager;
import forestry.api.fuels.MoistenerFuel;
import forestry.api.fuels.RainSubstrate;
import forestry.core.ForestryCore;
import forestry.core.config.Defaults;
import forestry.core.config.Version;
import forestry.core.network.PacketHandler;
import forestry.core.utils.FluidMap;
import forestry.core.utils.ItemStackMap;
/**
* Forestry Minecraft Mod
*
* @author SirSengir
*/
@Mod(
modid = Defaults.MOD,
name = "Forestry",
version = Version.VERSION,
dependencies = "required-after:Forge@[10.13.0.1180,);"
+ "after:Buildcraft|Core;"
+ "after:ExtrabiomesXL;"
+ "after:BiomesOPlenty;"
+ "after:IC2")
//, certificateFingerprint = Version.FINGERPRINT)
public class Forestry {
@Mod.Instance(Defaults.MOD)
public static Forestry instance;
public Forestry() {
FuelManager.fermenterFuel = new ItemStackMap<FermenterFuel>();
FuelManager.moistenerResource = new ItemStackMap<MoistenerFuel>();
FuelManager.rainSubstrate = new ItemStackMap<RainSubstrate>();
FuelManager.bronzeEngineFuel = new FluidMap<EngineBronzeFuel>();
FuelManager.copperEngineFuel = new ItemStackMap<EngineCopperFuel>();
}
@SidedProxy(clientSide = "forestry.core.ForestryClient", serverSide = "forestry.core.ForestryCore")
public static ForestryCore core = new ForestryCore();
public static PacketHandler packetHandler;
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
packetHandler = new PacketHandler();
core.preInit(event.getSourceFile(), this);
}
@EventHandler
public void init(FMLInitializationEvent event) {
core.init(this);
}
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
core.postInit();
}
@EventHandler
public void serverStarting(FMLServerStartingEvent event) {
core.serverStarting(event.getServer());
}
/*@EventHandler
public void fingerprintWarning(FMLFingerprintViolationEvent event) {
Proxies.log.info("Fingerprint of the mod jar is invalid. The jar file was tampered with.");
FMLInterModComms.sendMessage("Railcraft", "securityViolation", "Fingerprint of jar file did not match.");
FMLInterModComms.sendMessage("Thaumcraft", "securityViolation", "Fingerprint of jar file did not match.");
FMLInterModComms.sendMessage("IC2", "securityViolation", "Fingerprint of jar file did not match.");
}*/
@EventHandler
public void processIMCMessages(IMCEvent event) {
core.processIMCMessages(event.getMessages());
}
}
+329
View File
@@ -0,0 +1,329 @@
/*******************************************************************************
* 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;
import java.util.Stack;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IApiaristTracker;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeekeepingLogic;
import forestry.api.genetics.IEffectData;
import forestry.api.genetics.IIndividual;
import forestry.core.EnumErrorCode;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryItem;
import forestry.core.proxy.Proxies;
import forestry.plugins.PluginApiculture;
public class BeekeepingLogic implements IBeekeepingLogic {
private static final int MAX_POLLINATION_ATTEMPTS = 20;
IBeeHousing housing;
// Breeding
private int breedingTime;
private final int totalBreedingTime = Defaults.APIARY_BREEDING_TIME;
private int throttle;
private IEffectData effectData[] = new IEffectData[2];
private IBee queen;
private IIndividual pollen;
private int attemptedPollinations = 0;
private final Stack<ItemStack> spawn = new Stack<ItemStack>();
public BeekeepingLogic(IBeeHousing housing) {
this.housing = housing;
}
// / SAVING & LOADING
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
breedingTime = nbttagcompound.getInteger("BreedingTime");
throttle = nbttagcompound.getInteger("Throttle");
NBTTagList nbttaglist = nbttagcompound.getTagList("Offspring", 10);
for (int i = 0; i < nbttaglist.tagCount(); i++) {
spawn.add(ItemStack.loadItemStackFromNBT(nbttaglist.getCompoundTagAt(i)));
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("BreedingTime", breedingTime);
nbttagcompound.setInteger("Throttle", throttle);
Stack<ItemStack> spawnCopy = (Stack)spawn.clone();
NBTTagList nbttaglist = new NBTTagList();
while (!spawnCopy.isEmpty()) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
spawnCopy.pop().writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
nbttagcompound.setTag("Offspring", nbttaglist);
}
// / STATE INFORMATION
@Override
public int getBreedingTime() {
return this.breedingTime;
}
@Override
public int getTotalBreedingTime() {
return this.totalBreedingTime;
}
@Override
public IBee getQueen() {
return this.queen;
}
@Override
public IBeeHousing getHousing() {
return this.housing;
}
@Override
public IEffectData[] getEffectData() {
return this.effectData;
}
/* UPDATING */
@Override
public void update() {
resetQueen(null);
// Still something to spawn, try it
while (!spawn.isEmpty()) {
ItemStack next = spawn.peek();
if (housing.addProduct(next, true)) {
spawn.pop();
housing.setErrorState(EnumErrorCode.OK.ordinal());
} else
housing.setErrorState(EnumErrorCode.NOSPACE.ordinal());
return;
}
// No queen? And no princess?
if (housing.getQueen() == null) {
housing.setErrorState(EnumErrorCode.NOQUEEN.ordinal());
return;
}
// Princess available? Try to breed!
if (ForestryItem.beePrincessGE.isItemEqual(housing.getQueen())) {
if (ForestryItem.beeDroneGE.isItemEqual(housing.getDrone()))
housing.setErrorState(EnumErrorCode.NODRONE.ordinal());
else
housing.setErrorState(EnumErrorCode.OK.ordinal());
tickBreed();
return;
}
// Can't continue if an item of the wrong type is in the queen slot.
if (!ForestryItem.beeQueenGE.isItemEqual(housing.getQueen())) {
housing.setErrorState(EnumErrorCode.NOQUEEN.ordinal());
return;
}
IBee queen = PluginApiculture.beeInterface.getMember(housing.getQueen());
// Kill dying queens
if (!queen.isAlive()) {
killQueen(queen);
housing.setErrorState(EnumErrorCode.OK.ordinal());
return;
}
resetQueen(queen);
// Not while raining, at night or without light
EnumErrorCode state = EnumErrorCode.values()[queen.isWorking(housing)];
if (state != EnumErrorCode.OK) {
housing.setErrorState(state.ordinal());
return;
} else if (housing.getErrorOrdinal() != EnumErrorCode.NOFLOWER.ordinal())
housing.setErrorState(EnumErrorCode.OK.ordinal());
// Effects only fire when queen can work.
effectData = queen.doEffect(effectData, housing);
// We have a queen, work!
throttle++;
if (throttle >= PluginApiculture.beeCycleTicks)
throttle = 0;
else
return;
// Need a flower
if (!queen.hasFlower(housing)) {
housing.setErrorState(EnumErrorCode.NOFLOWER.ordinal());
return;
} else
housing.setErrorState(EnumErrorCode.OK.ordinal());
// Produce and add stacks
ItemStack[] products = queen.produceStacks(housing);
housing.wearOutEquipment(1);
for (ItemStack stack : products) {
housing.addProduct(stack, false);
}
// Plant a flower
queen.plantFlowerRandom(housing);
// Get pollen if none available yet
if (pollen == null) {
pollen = queen.retrievePollen(housing);
attemptedPollinations = 0;
if (pollen != null) {
if (housing.onPollenRetrieved(queen, pollen, false))
pollen = null;
}
}
if (pollen != null) {
attemptedPollinations++;
if (queen.pollinateRandom(housing, pollen)
|| attemptedPollinations >= MAX_POLLINATION_ATTEMPTS) {
pollen = null;
}
}
// Age the queen
queen.age(housing.getWorld(), housing.getLifespanModifier(queen.getGenome(), queen.getMate(), 0f));
// Write the changed queen back into the item stack.
NBTTagCompound nbttagcompound = new NBTTagCompound();
queen.writeToNBT(nbttagcompound);
housing.getQueen().setTagCompound(nbttagcompound);
return;
}
private void resetQueen(IBee bee) {
this.queen = bee;
}
// / BREEDING
private void tickBreed() {
if (!tryBreed()) {
breedingTime = 0;
return;
}
if (breedingTime < totalBreedingTime)
breedingTime++;
if (breedingTime < totalBreedingTime)
return;
// Breeding done, create new queen if slot available
if (!ForestryItem.beePrincessGE.isItemEqual(housing.getQueen()))
return;
// Replace
IBee princess = PluginApiculture.beeInterface.getMember(housing.getQueen());
IBee drone = PluginApiculture.beeInterface.getMember(housing.getDrone());
princess.mate(drone);
NBTTagCompound nbttagcompound = new NBTTagCompound();
princess.writeToNBT(nbttagcompound);
ItemStack queen = ForestryItem.beeQueenGE.getItemStack();
queen.setTagCompound(nbttagcompound);
housing.setQueen(queen);
housing.onQueenChange(housing.getQueen());
// Register the new queen with the breeding tracker
PluginApiculture.beeInterface.getBreedingTracker(housing.getWorld(), housing.getOwnerName()).registerQueen(princess);
// Remove drone
housing.getDrone().stackSize--;
if (housing.getDrone().stackSize <= 0)
housing.setDrone(null);
// Reset breeding time
breedingTime = 0;
}
private boolean tryBreed() {
if (housing.getDrone() == null || housing.getQueen() == null)
return false;
if (!ForestryItem.beeDroneGE.isItemEqual(housing.getDrone()) || !ForestryItem.beePrincessGE.isItemEqual(housing.getQueen()))
return false;
if (!housing.canBreed())
return false;
return true;
}
private void killQueen(IBee queen) {
if (queen.canSpawn()) {
spawnOffspring(queen);
housing.getQueen().stackSize = 0;
housing.setQueen(null);
} else {
Proxies.log.warning("Tried to spawn offspring off an unmated queen. Devolving her to a princess.");
ItemStack convert = ForestryItem.beePrincessGE.getItemStack();
NBTTagCompound nbttagcompound = new NBTTagCompound();
queen.writeToNBT(nbttagcompound);
convert.setTagCompound(nbttagcompound);
spawn.add(convert);
housing.setQueen(null);
}
housing.onQueenChange(housing.getQueen());
}
/**
* Creates the succeeding princess and between one and three drones.
*/
private void spawnOffspring(IBee queen) {
Stack<ItemStack> offspring = new Stack<ItemStack>();
IApiaristTracker breedingTracker = PluginApiculture.beeInterface.getBreedingTracker(housing.getWorld(), housing.getOwnerName());
housing.onQueenDeath(getQueen());
// Princess
IBee heiress = queen.spawnPrincess(housing);
if (heiress != null) {
ItemStack princess = PluginApiculture.beeInterface.getMemberStack(heiress, EnumBeeType.PRINCESS.ordinal());
breedingTracker.registerPrincess(heiress);
offspring.push(princess);
}
// Drones
IBee[] larvae = queen.spawnDrones(housing);
for (IBee larva : larvae) {
ItemStack drone = PluginApiculture.beeInterface.getMemberStack(larva, EnumBeeType.DRONE.ordinal());
breedingTracker.registerDrone(larva);
offspring.push(drone);
}
while (!offspring.isEmpty()) {
ItemStack spawned = offspring.pop();
if (!housing.addProduct(spawned, true))
spawn.add(spawned);
}
housing.onPostQueenDeath(getQueen());
}
}
@@ -0,0 +1,252 @@
/*******************************************************************************
* 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;
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.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IApiaristTracker;
import forestry.api.apiculture.IBeekeepingMode;
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.PluginApiculture;
public class CommandBeekeepingMode extends CommandMC {
String[] modeStrings;
public CommandBeekeepingMode() {
modeStrings = new String[PluginApiculture.beeInterface.getBeekeepingModes().size()];
for (int i = 0; i < PluginApiculture.beeInterface.getBeekeepingModes().size(); i++)
modeStrings[i] = PluginApiculture.beeInterface.getBeekeepingModes().get(i).getName();
}
@Override
public int compareTo(Object arg0) {
return this.getCommandName().compareTo(((ICommand) arg0).getCommandName());
}
@Override
public String getCommandName() {
return "beekeeping";
}
@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("Type '" + this.getCommandUsage(sender) + "' for help.");
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];
IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(desired);
if (mode == null)
throw new CommandException("A bekeeping mode called '%s' is not available.", desired);
PluginApiculture.beeInterface.setBeekeepingMode(world, mode.getName());
func_152373_a(sender, this, "Beekeeping mode set to %s.", 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, "Format: '/" + this.getCommandName() + " <command> <arguments>'");
sendChatMessage(sender, "Available commands:");
sendChatMessage(sender, "- list [<world-#>]: lists current and available beekeeping modes.");
sendChatMessage(sender, "- info <mode-name> : information on beekeeping mode.");
sendChatMessage(sender, "- set [<world-#>] <mode-name>: set beekeeping mode for world.");
sendChatMessage(sender, "- save [<world-#>] <player-name>: save beekeeping statistics for the given player.");
}
}
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("Beekeeping statistics for %s on %s:", player, DateFormat.getInstance().format(new Date())));
statistics.add("");
statistics.add("MODE: " + PluginApiculture.beeInterface.getBeekeepingMode(world).getName());
statistics.add("");
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(player);
IApiaristTracker tracker = PluginApiculture.beeInterface.getBreedingTracker(world, profile);
if (tracker == null)
statistics.add("No statistics found.");
else {
statistics.add("BRED:");
statistics.add("-----");
statistics.add("");
statistics.add("Queens:\t\t" + tracker.getQueenCount());
statistics.add("Princesses:\t" + tracker.getPrincessCount());
statistics.add("Drones:\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);
statistics.add(String.format("SPECIES (%s):", species.size()));
statistics.add("-------------");
statistics.add("");
for (IAlleleBeeSpecies 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(IAlleleBeeSpecies species, IApiaristTracker 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: " + PluginApiculture.beeInterface.getBeekeepingMode(world).getName() + " (#" + world.getWorldInfo().getSaveVersion() + ")");
String help = "";
for (IBeekeepingMode mode : PluginApiculture.beeInterface.getBeekeepingModes()) {
if (!help.isEmpty())
help += ", ";
help += mode.getName();
}
sendChatMessage(sender, "Available modes: " + help);
return;
}
private void listModeInfo(ICommandSender sender, String[] arguments) {
if (arguments.length <= 1)
throw new WrongUsageException("/" + this.getCommandName() + " info <mode-name>");
IBeekeepingMode found = null;
for (IBeekeepingMode mode : PluginApiculture.beeInterface.getBeekeepingModes())
if (mode.getName().equalsIgnoreCase(arguments[1])) {
found = mode;
break;
}
if (found == null)
throw new CommandException("No beekeeping 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);
}
}
+122
View File
@@ -0,0 +1,122 @@
/*******************************************************************************
* 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;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
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.api.genetics.IAlleleSpecies;
import forestry.core.utils.CommandMC;
import forestry.plugins.PluginApiculture;
public class CommandGiveBee extends CommandMC {
EnumBeeType type;
public CommandGiveBee(EnumBeeType type) {
this.type = type;
}
@Override
public String getCommandName() {
return "give" + type.toString().toLowerCase();
}
@Override
public String getCommandUsage(ICommandSender par1ICommandSender) {
return "/" + getCommandName() + " <player-name> <species-name>";
}
@Override
public void processCommand(ICommandSender sender, String[] arguments) {
if (arguments.length >= 2) {
EntityPlayer player = getPlayer(sender, arguments[0]);
String parameter = arguments[1];
IAlleleBeeSpecies species = null;
search: for (String uid : AlleleManager.alleleRegistry.getRegisteredAlleles().keySet()) {
if (!uid.equals(parameter))
continue;
if (AlleleManager.alleleRegistry.getAllele(uid) instanceof IAlleleBeeSpecies) {
species = (IAlleleBeeSpecies) AlleleManager.alleleRegistry.getAllele(uid);
break search;
}
}
search: if (species == null)
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values())
if (allele instanceof IAlleleBeeSpecies)
if (((IAlleleBeeSpecies) allele).getName().equals(parameter)) {
species = (IAlleleBeeSpecies) allele;
break search;
}
if (species == null)
throw new SpeciesNotFoundException(parameter);
IAllele[] template = PluginApiculture.beeInterface.getTemplate(species.getUID());
if (template == null)
throw new TemplateNotFoundException(species);
IBeeGenome genome = PluginApiculture.beeInterface.templateAsGenome(template);
IBee bee = PluginApiculture.beeInterface.getBee(player.worldObj, genome);
if(this.type == EnumBeeType.QUEEN)
bee.mate(bee);
ItemStack beestack = PluginApiculture.beeInterface.getMemberStack(bee, type.ordinal());
player.dropPlayerItemWithRandomChoice(beestack, true);
func_152373_a(sender, this, "Player %s was given a %s bee.", player.getCommandSenderName(), ((IAlleleSpecies) template[0]).getName());
} else
throw new WrongUsageException("/" + getCommandName() + " <player-name> <species-name>");
}
/**
* Adds the strings available in this command to the given list of tab completion options.
*/
@SuppressWarnings("rawtypes")
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] parameters) {
if (parameters.length == 1)
return getListOfStringsMatchingLastWord(parameters, this.getPlayers());
else if (parameters.length == 2)
return getListOfStringsMatchingLastWord(parameters, this.getSpecies());
else
return null;
}
protected String[] getSpecies() {
List<String> species = new ArrayList<String>();
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values())
if (allele instanceof IAlleleBeeSpecies)
species.add(((IAlleleSpecies) allele).getName());
return species.toArray(new String[] {});
}
}
+84
View File
@@ -0,0 +1,84 @@
/*******************************************************************************
* 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;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
public class FlowerProviderCacti implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// Specific check for flower pots.
if (block == Blocks.flower_pot)
return checkFlowerPot(world.getBlockMetadata(x, y, z));
return block == Blocks.cactus;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
return pollinatable.getPlantType().contains(EnumPlantType.Desert);
}
private boolean checkFlowerPot(int meta) {
if (meta == 9)
return true;
else
return false;
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (block == Blocks.flower_pot && world.getBlockMetadata(x, y, z) == 0)
return growInPot(world, x, y, z);
return false;
}
private boolean growInPot(World world, int x, int y, int z) {
if (world.rand.nextBoolean())
world.setBlock(x, y, z, Blocks.flower_pot, 9, Defaults.FLAG_BLOCK_SYNCH);
else
world.setBlock(x, y, z, Blocks.flower_pot, 10, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.cacti");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.cactus) };
}
}
+61
View File
@@ -0,0 +1,61 @@
/*******************************************************************************
* 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;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.utils.StringUtil;
public class FlowerProviderEnd implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == Blocks.dragon_egg;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.end");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.dragon_egg) };
}
}
+79
View File
@@ -0,0 +1,79 @@
/*******************************************************************************
* 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;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
public class FlowerProviderGourd implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == Blocks.pumpkin_stem || block == Blocks.melon_stem;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// We only grow wheat, we don't plant it
if (block != Blocks.pumpkin_stem && block != Blocks.melon_stem)
return false;
int meta = world.getBlockMetadata(x, y, z);
if (meta > 6)
return false;
if (meta < 6)
meta += 2;
else
meta = 7;
world.setBlockMetadataWithNotify(x, y, z, meta, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.gourd");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.wheat, 1, 8) };
}
}
@@ -0,0 +1,85 @@
/*******************************************************************************
* 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;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
public class FlowerProviderJungle implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
// Specific check for flower pots.
if (block == Blocks.flower_pot)
return checkFlowerPot(meta);
return block == Blocks.vine || (block == Blocks.tallgrass && meta == 2);
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
private boolean checkFlowerPot(int meta) {
if (meta == 11)
return true;
else
return false;
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (block == Blocks.flower_pot)
return growInPot(world, x, y, z);
return false;
}
private boolean growInPot(World world, int x, int y, int z) {
world.setBlock(x, y, z, Blocks.flower_pot, 11, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.jungle");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.vine), new ItemStack(Blocks.tallgrass, 1, 2) };
}
}
@@ -0,0 +1,103 @@
/*******************************************************************************
* 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;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
public class FlowerProviderMushroom implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// Specific check for flower pots.
if (block == Blocks.flower_pot)
return checkFlowerPot(world.getBlockMetadata(x, y, z));
return block == Blocks.brown_mushroom || block == Blocks.red_mushroom;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
private boolean checkFlowerPot(int meta) {
if (meta == 7 || meta == 8)
return true;
else
return false;
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (!block.isAir(world, x, y, z))
if (block == Blocks.flower_pot)
return growInPot(world, x, y, z);
else
return false;
// Check ground
Block ground = world.getBlock(x, y - 1, z);
if (ground != Blocks.mycelium)
return false;
Block mushroom;
if (world.rand.nextBoolean())
mushroom = Blocks.brown_mushroom;
else
mushroom = Blocks.red_mushroom;
world.setBlock(x, y, z, mushroom, 0, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
private boolean growInPot(World world, int x, int y, int z) {
if (world.rand.nextBoolean())
world.setBlock(x, y, z, Blocks.flower_pot, 7, Defaults.FLAG_BLOCK_SYNCH);
else
world.setBlock(x, y, z, Blocks.flower_pot, 8, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.mushroom");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.brown_mushroom), new ItemStack(Blocks.red_mushroom) };
}
}
@@ -0,0 +1,76 @@
/*******************************************************************************
* 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;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
public class FlowerProviderNetherwart implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == Blocks.nether_wart;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
return pollinatable.getPlantType().contains(EnumPlantType.Nether);
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// We only grow netherwart, we don't plant it
if (block != Blocks.nether_wart)
return false;
int meta = world.getBlockMetadata(x, y, z);
if (meta >= 3)
return false;
if (meta == 2)
meta = 3;
else
meta = 2;
world.setBlockMetadataWithNotify(x, y, z, meta, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.nether");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.nether_wart) };
}
}
@@ -0,0 +1,112 @@
/*******************************************************************************
* 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;
import java.util.Collections;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.apiculture.FlowerManager;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StackUtils;
import forestry.core.utils.StringUtil;
public class FlowerProviderVanilla implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
int meta = world.getBlockMetadata(x, y, z);
// Specific check for flower pots.
if (block == Blocks.flower_pot)
return checkFlowerPot(meta);
ItemStack flower = new ItemStack(block, 1, meta);
for (ItemStack stack : FlowerManager.plainFlowers)
if (flower.isItemEqual(stack))
return true;
return false;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
private boolean checkFlowerPot(int meta) {
if (meta == 1 || meta == 2)
return true;
else
return false;
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
if (!block.isAir(world, x, y, z))
if (block == Blocks.flower_pot && world.getBlockMetadata(x, y, z) == 0)
return growInPot(world, x, y, z);
else
return false;
// Check ground
Block ground = world.getBlock(x, y - 1, z);
if (ground != Blocks.dirt && ground != Blocks.grass)
return false;
// Determine flower to plant
Collections.shuffle(FlowerManager.plainFlowers);
ItemStack flower = FlowerManager.plainFlowers.get(world.rand.nextInt(FlowerManager.plainFlowers.size() - 1));
world.setBlock(x, y, z, StackUtils.getBlock(flower), flower.getItemDamage(), Defaults.FLAG_BLOCK_SYNCH);
return true;
}
private boolean growInPot(World world, int x, int y, int z) {
if (world.rand.nextBoolean())
world.setBlock(x, y, z, Blocks.flower_pot, 1, Defaults.FLAG_BLOCK_SYNCH);
else
world.setBlock(x, y, z, Blocks.flower_pot, 2, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.vanilla");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return FlowerManager.plainFlowers.toArray(new ItemStack[0]);
}
}
+79
View File
@@ -0,0 +1,79 @@
/*******************************************************************************
* 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;
import java.util.EnumSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
public class FlowerProviderWheat implements IFlowerProvider {
@Override
public boolean isAcceptedFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
return block == Blocks.wheat;
}
@Override
public boolean isAcceptedPollinatable(World world, IPollinatable pollinatable) {
EnumSet<EnumPlantType> types = pollinatable.getPlantType();
return types.size() > 1 || !types.contains(EnumPlantType.Nether);
}
@Override
public boolean growFlower(World world, IIndividual individual, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
// We only grow wheat, we don't plant it
if (block != Blocks.wheat)
return false;
int meta = world.getBlockMetadata(x, y, z);
if (meta > 6)
return false;
if (meta < 6)
meta += 2;
else
meta = 7;
world.setBlockMetadataWithNotify(x, y, z, meta, Defaults.FLAG_BLOCK_SYNCH);
return true;
}
@Override
public String getDescription() {
return StringUtil.localize("flowers.wheat");
}
@Override
public ItemStack[] affectProducts(World world, IIndividual individual, int x, int y, int z, ItemStack[] products) {
return products;
}
@Override
public ItemStack[] getItemStacks() {
return new ItemStack[] { new ItemStack(Blocks.wheat, 1, 8) };
}
}
+167
View File
@@ -0,0 +1,167 @@
/*******************************************************************************
* 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;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import forestry.apiculture.gadgets.TileAlvearyHygroregulator;
import forestry.apiculture.gadgets.TileAlvearyPlain;
import forestry.apiculture.gadgets.TileAlvearySieve;
import forestry.apiculture.gadgets.TileAlvearySwarmer;
import forestry.apiculture.gadgets.TileApiary;
import forestry.apiculture.gadgets.TileBeehouse;
import forestry.apiculture.genetics.BeeHelper;
import forestry.apiculture.gui.ContainerAlveary;
import forestry.apiculture.gui.ContainerAlvearyHygroregulator;
import forestry.apiculture.gui.ContainerAlvearySieve;
import forestry.apiculture.gui.ContainerAlvearySwarmer;
import forestry.apiculture.gui.ContainerApiary;
import forestry.apiculture.gui.ContainerBeealyzer;
import forestry.apiculture.gui.ContainerHabitatLocator;
import forestry.apiculture.gui.ContainerImprinter;
import forestry.apiculture.gui.GuiAlveary;
import forestry.apiculture.gui.GuiAlvearyHygroregulator;
import forestry.apiculture.gui.GuiAlvearySieve;
import forestry.apiculture.gui.GuiAlvearySwarmer;
import forestry.apiculture.gui.GuiApiary;
import forestry.apiculture.gui.GuiBeealyzer;
import forestry.apiculture.gui.GuiHabitatLocator;
import forestry.apiculture.gui.GuiImprinter;
import forestry.apiculture.items.ItemBeealyzer.BeealyzerInventory;
import forestry.apiculture.items.ItemBiomefinder.BiomefinderInventory;
import forestry.apiculture.items.ItemImprinter.ImprinterInventory;
import forestry.core.GuiHandlerBase;
import forestry.core.network.GuiId;
import forestry.plugins.PluginApiculture;
public class GuiHandlerApiculture extends GuiHandlerBase {
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
int cleanId = decodeGuiID(id);
int guiData = decodeGuiData(id);
if (cleanId >= GuiId.values().length)
return null;
ItemStack equipped;
switch (GuiId.values()[cleanId]) {
case AlvearyGUI:
return new GuiAlveary(player.inventory, (TileAlvearyPlain) getTileForestry(world, x, y, z));
case AlvearySieveGUI:
return new GuiAlvearySieve(player.inventory, (TileAlvearySieve) getTileForestry(world, x, y, z));
case AlvearySwarmerGUI:
return new GuiAlvearySwarmer(player.inventory, (TileAlvearySwarmer) getTileForestry(world, x, y, z));
case ApiaristChestGUI:
return getNaturalistChestGui(BeeHelper.UID, player, world, x, y, z, guiData);
case ApiaryGUI:
return new GuiApiary(player.inventory, (TileApiary) getTileForestry(world, x, y, z));
case BeealyzerGUI:
equipped = getEquippedItem(player);
if (equipped == null)
return null;
return new GuiBeealyzer(player, new BeealyzerInventory(player, equipped));
case BeehouseGUI:
return new GuiApiary(player.inventory, (TileBeehouse) getTileForestry(world, x, y, z));
case HabitatLocatorGUI:
equipped = getEquippedItem(player);
if (equipped == null)
return null;
return new GuiHabitatLocator(player.inventory, new BiomefinderInventory(equipped));
case HygroregulatorGUI:
return new GuiAlvearyHygroregulator(player.inventory, (TileAlvearyHygroregulator) getTileForestry(world, x, y, z));
case ImprinterGUI:
return new GuiImprinter(player.inventory, new ImprinterInventory(player));
default:
return null;
}
}
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
int cleanId = decodeGuiID(id);
int guiData = decodeGuiData(id);
if (cleanId >= GuiId.values().length)
return null;
ItemStack equipped;
switch (GuiId.values()[cleanId]) {
case AlvearyGUI:
synchApiaristTracker(world, player);
return new ContainerAlveary(player.inventory, (TileAlvearyPlain) getTileForestry(world, x, y, z));
case AlvearySieveGUI:
return new ContainerAlvearySieve(player.inventory, (TileAlvearySieve) getTileForestry(world, x, y, z));
case AlvearySwarmerGUI:
return new ContainerAlvearySwarmer(player.inventory, (TileAlvearySwarmer) getTileForestry(world, x, y, z));
case ApiaristChestGUI:
return getNaturalistChestContainer(BeeHelper.UID, player, world, x, y, z, guiData);
case ApiaryGUI:
synchApiaristTracker(world, player);
return new ContainerApiary(player.inventory, (TileApiary) getTileForestry(world, x, y, z), true);
case BeealyzerGUI:
equipped = getEquippedItem(player);
if (equipped == null)
return null;
synchApiaristTracker(world, player);
return new ContainerBeealyzer(player.inventory, new BeealyzerInventory(player, equipped));
case BeehouseGUI:
synchApiaristTracker(world, player);
return new ContainerApiary(player.inventory, (TileBeehouse) getTileForestry(world, x, y, z), false);
case HabitatLocatorGUI:
equipped = getEquippedItem(player);
if (equipped == null)
return null;
return new ContainerHabitatLocator(player.inventory, new BiomefinderInventory(equipped));
case HygroregulatorGUI:
return new ContainerAlvearyHygroregulator(player.inventory, (TileAlvearyHygroregulator) getTileForestry(world, x, y, z));
case ImprinterGUI:
synchApiaristTracker(world, player);
return new ContainerImprinter(player.inventory, new ImprinterInventory(player));
default:
return null;
}
}
private void synchApiaristTracker(World world, EntityPlayer player) {
PluginApiculture.beeInterface.getBreedingTracker(world, player.getGameProfile()).synchToPlayer(player);
}
}
+25
View File
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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;
import net.minecraft.block.material.MapColor;
import net.minecraft.block.material.Material;
public class MaterialBeehive extends Material {
public MaterialBeehive(boolean noHarvest) {
super(MapColor.stoneColor);
if (noHarvest)
this.setRequiresTool();
setImmovableMobility();
}
}
@@ -0,0 +1,54 @@
/*******************************************************************************
* 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;
import java.io.DataInputStream;
import net.minecraft.entity.player.EntityPlayer;
import forestry.apiculture.gui.ContainerImprinter;
import forestry.core.interfaces.IPacketHandler;
import forestry.core.network.PacketCoordinates;
import forestry.core.network.PacketIds;
import forestry.core.proxy.Proxies;
public class PacketHandlerApiculture implements IPacketHandler {
@Override
public void onPacketData(int packetID, DataInputStream data, EntityPlayer player) {
try {
switch (packetID) {
case PacketIds.HABITAT_BIOME_POINTER:
PacketCoordinates packetC = new PacketCoordinates();
packetC.readData(data);
Proxies.common.setBiomefinderCoordinates(player, packetC.getCoordinates());
break;
case PacketIds.IMPRINT_SELECTION_GET:
onImprintSelectionGet(player);
break;
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void onImprintSelectionGet(EntityPlayer playerEntity) {
if (!(playerEntity.openContainer instanceof ContainerImprinter))
return;
((ContainerImprinter) playerEntity.openContainer).sendSelection(playerEntity);
}
}
@@ -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.apiculture;
import net.minecraft.world.World;
import forestry.core.interfaces.ISaveEventHandler;
import forestry.plugins.PluginApiculture;
public class SaveEventHandlerApiculture implements ISaveEventHandler {
@Override
public void onWorldLoad(World world) {
PluginApiculture.beeInterface.resetBeekeepingMode();
}
@Override
public void onWorldSave(World world) {
}
@Override
public void onWorldUnload(World world) {
}
}
@@ -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.apiculture;
import net.minecraft.command.CommandException;
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);
}
}
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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;
import net.minecraft.command.CommandException;
import forestry.api.genetics.IAlleleSpecies;
public class TemplateNotFoundException extends CommandException {
private static final long serialVersionUID = 1L;
public TemplateNotFoundException(IAlleleSpecies species) {
super("Could not find template for species %s with UID %s", species.getName(), species.getUID());
}
}
@@ -0,0 +1,77 @@
/*******************************************************************************
* 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;
import java.util.List;
import java.util.Random;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.village.MerchantRecipe;
import net.minecraft.village.MerchantRecipeList;
import net.minecraft.world.gen.structure.MapGenStructureIO;
import net.minecraft.world.gen.structure.StructureVillagePieces;
import cpw.mods.fml.common.registry.VillagerRegistry.IVillageCreationHandler;
import cpw.mods.fml.common.registry.VillagerRegistry.IVillageTradeHandler;
import forestry.api.apiculture.EnumBeeType;
import forestry.apiculture.genetics.BeeTemplates;
import forestry.apiculture.items.ItemHoneycomb;
import forestry.apiculture.worldgen.ComponentVillageBeeHouse;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryBlock;
import forestry.core.config.ForestryItem;
import forestry.plugins.PluginApiculture;
public class VillageHandlerApiculture implements IVillageCreationHandler, IVillageTradeHandler {
public static void registerVillageComponents() {
try {
MapGenStructureIO.func_143031_a(ComponentVillageBeeHouse.class, "Forestry:BeeHouse");
} catch (Throwable e) {
}
}
@SuppressWarnings("unchecked")
@Override
public void manipulateTradesForVillager(EntityVillager villager, MerchantRecipeList recipeList, Random random) {
recipeList.add(new MerchantRecipe(ForestryItem.beePrincessGE.getItemStack(1, Defaults.WILDCARD), new ItemStack(Items.emerald, 1)));
recipeList.add(new MerchantRecipe(new ItemStack(Items.wheat, 2), ItemHoneycomb.getRandomComb(1, random, false)));
recipeList.add(new MerchantRecipe(new ItemStack(Blocks.log, 24, Defaults.WILDCARD), new ItemStack(ForestryBlock.apiculture, 1,
Defaults.DEFINITION_APIARY_META)));
recipeList.add(new MerchantRecipe(new ItemStack(Items.emerald, 1), ForestryItem.frameProven.getItemStack(6)));
recipeList.add(new MerchantRecipe(new ItemStack(Items.emerald, 12), ForestryItem.beePrincessGE.getItemStack(1, Defaults.WILDCARD),
PluginApiculture.beeInterface.getMemberStack(
PluginApiculture.beeInterface.getBee(villager.worldObj, PluginApiculture.beeInterface.templateAsGenome(BeeTemplates.getMonasticTemplate())),
EnumBeeType.DRONE.ordinal())));
}
@Override
public StructureVillagePieces.PieceWeight getVillagePieceWeight(Random random, int size) {
return new StructureVillagePieces.PieceWeight(ComponentVillageBeeHouse.class, 15, MathHelper.getRandomIntegerInRange(random, 0 + size, 1 + size));
}
@Override
public Class<?> getComponentClass() {
return ComponentVillageBeeHouse.class;
}
@SuppressWarnings("rawtypes")
@Override
public Object buildComponent(StructureVillagePieces.PieceWeight villagePiece, StructureVillagePieces.Start startPiece, List pieces, Random random, int p1, int p2,
int p3, int p4, int p5) {
return ComponentVillageBeeHouse.buildComponent(startPiece, pieces, random, p1, p2, p3, p4, p5);
}
}
+91
View File
@@ -0,0 +1,91 @@
/*******************************************************************************
* 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.entities;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.passive.IAnimals;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBee;
import forestry.core.config.Defaults;
import forestry.core.utils.ForestryResource;
import forestry.plugins.PluginApiculture;
public class EntityBee extends EntityCreature implements IAnimals {
private static final String DEFAULT_TEXTURE = Defaults.TEXTURE_PATH_ENTITIES + "/bees/honeyBee.png";
IBee contained;
IAlleleBeeSpecies species;
EnumBeeType type = EnumBeeType.DRONE;
private String beeTexture = DEFAULT_TEXTURE;
private long lastUpdate;
public EntityBee(World world) {
super(world);
}
private void resetAppearance() {
beeTexture = species.getEntityTexture();
}
public EntityBee setIndividual(IBee bee) {
if(bee != null)
contained = bee;
else
contained = PluginApiculture.beeInterface.templateAsIndividual(PluginApiculture.beeInterface.getDefaultTemplate());
//isImmuneToFire = contained.getGenome().getFireResist();
setSpecies(contained.getGenome().getPrimary());
//dataWatcher.updateObject(DATAWATCHER_ID_SPECIES, species.getUID());
//dataWatcher.updateObject(DATAWATCHER_ID_SCALE, (int)(contained.getSize() * 100));
return this;
}
public IBee getBee() {
return contained;
}
public EntityBee setType(EnumBeeType type) {
this.type = type;
return this;
}
public EnumBeeType getType() {
return type;
}
public EntityBee setSpecies(IAlleleBeeSpecies species) {
this.species = species;
resetAppearance();
lastUpdate = worldObj.getTotalWorldTime();
return this;
}
@SideOnly(Side.CLIENT)
private ResourceLocation textureResource;
private long lastTextureUpdate;
@SideOnly(Side.CLIENT)
public ResourceLocation getTexture() {
if(textureResource == null || lastTextureUpdate != lastUpdate)
textureResource = new ForestryResource(beeTexture);
return textureResource;
}
}
+232
View File
@@ -0,0 +1,232 @@
/*******************************************************************************
* 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.gadgets;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.core.Tabs;
import forestry.apiculture.MaterialBeehive;
import forestry.core.gadgets.BlockStructure;
import forestry.core.render.TextureManager;
public class BlockAlveary extends BlockStructure {
public BlockAlveary() {
super(new MaterialBeehive(false));
setHardness(1.0f);
setCreativeTab(Tabs.tabApiculture);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
for (int i = 0; i < 8; i++) {
if (i == 1)
continue;
list.add(new ItemStack(item, 1, i));
}
}
@Override
public int getRenderType() {
return 0;
}
@Override
public boolean renderAsNormalBlock() {
return true;
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> drop = new ArrayList<ItemStack>();
drop.add(new ItemStack(this, 1, metadata != 1 ? metadata : 0));
return drop;
}
@Override
public int getDamageValue(World world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
return meta != 1 ? meta : 0;
}
/* TILE ENTITY CREATION */
@Override
public TileEntity createTileEntity(World world, int metadata) {
switch (metadata) {
case TileAlvearySwarmer.BLOCK_META:
return new TileAlvearySwarmer();
case TileAlvearyFan.BLOCK_META:
return new TileAlvearyFan();
case TileAlvearyHeater.BLOCK_META:
return new TileAlvearyHeater();
case TileAlvearyHygroregulator.BLOCK_META:
return new TileAlvearyHygroregulator();
case TileAlvearyStabiliser.BLOCK_META:
return new TileAlvearyStabiliser();
case TileAlvearySieve.BLOCK_META:
return new TileAlvearySieve();
default:
return new TileAlvearyPlain();
}
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return createTileEntity(world, meta);
}
/* ICONS */
public static final int PLAIN = 0;
public static final int ENTRANCE = 1;
public static final int BOTTOM = 2;
public static final int LEFT = 3;
public static final int RIGHT = 4;
public static final int TX_55_SWOF = 5;
public static final int TX_56_SWON = 6;
public static final int TX_57_HTOF = 7;
public static final int TX_58_HTON = 8;
public static final int TX_71_FNOF = 9;
public static final int TX_72_FNON = 10;
public static final int TX_73_VLVE = 11;
public static final int STABILISER = 12;
public static final int SIEVE = 13;
@SideOnly(Side.CLIENT)
private IIcon[] icons;
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister register) {
icons = new IIcon[14];
icons[0] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.plain");
icons[1] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.entrance");
icons[2] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.bottom");
icons[3] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.left");
icons[4] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.right");
icons[5] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.swarmer.off");
icons[6] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.swarmer.on");
icons[7] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.heater.off");
icons[8] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.heater.on");
icons[9] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.fan.off");
icons[10] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.fan.on");
icons[11] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.valve");
icons[12] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.stabiliser");
icons[13] = TextureManager.getInstance().registerTex(register, "apiculture/alveary.sieve");
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(int side, int metadata) {
if ((metadata <= 1
|| metadata == TileAlvearySieve.BLOCK_META || metadata == TileAlvearySwarmer.BLOCK_META || metadata == TileAlvearyStabiliser.BLOCK_META)
&& (side == 1 || side == 0))
return icons[BOTTOM];
switch (metadata) {
case 1:
return icons[ENTRANCE];
case TileAlvearySwarmer.BLOCK_META:
return icons[TX_55_SWOF];
case TileAlvearyFan.BLOCK_META:
return icons[TX_71_FNOF];
case TileAlvearyHeater.BLOCK_META:
return icons[TX_57_HTOF];
case TileAlvearyHygroregulator.BLOCK_META:
return icons[TX_73_VLVE];
case TileAlvearyStabiliser.BLOCK_META:
return icons[STABILISER];
case TileAlvearySieve.BLOCK_META:
return icons[SIEVE];
default:
return icons[PLAIN];
}
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
int meta = world.getBlockMetadata(x, y, z);
if (meta == 1)
return this.getIcon(side, meta);
else if (meta > 1)
return getBlockTextureFromSideAndTile(world, x, y, z, side);
Block blockXP = world.getBlock(x + 1, y, z);
Block blockXM = world.getBlock(x - 1, y, z);
if (blockXP == this && blockXM != this) {
if (world.getBlockMetadata(x + 1, y, z) == 1) {
if (world.getBlock(x, y, z + 1) != this)
return switchForSide(42, side);
else
return switchForSide(41, side);
} else
return this.getIcon(side, meta);
} else if (blockXP != this && blockXM == this)
if (world.getBlockMetadata(x - 1, y, z) == 1) {
if (world.getBlock(x, y, z + 1) != this)
return switchForSide(41, side);
else
return switchForSide(42, side);
} else
return this.getIcon(side, meta);
return this.getIcon(side, meta);
}
@SideOnly(Side.CLIENT)
private IIcon getBlockTextureFromSideAndTile(IBlockAccess world, int x, int y, int z, int side) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile == null || !(tile instanceof TileAlveary))
return getIcon(side, 0);
return icons[((TileAlveary) tile).getIcon(side, world.getBlockMetadata(x, y, z))];
}
@SideOnly(Side.CLIENT)
private IIcon switchForSide(int textureId, int side) {
if (side == 4 || side == 5) {
if (textureId == 41)
return icons[LEFT];
else
return icons[RIGHT];
} else if (textureId == 41)
return icons[RIGHT];
else
return icons[LEFT];
}
}
@@ -0,0 +1,169 @@
/*******************************************************************************
* 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.gadgets;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.block.BlockContainer;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.IHiveDrop;
import forestry.api.core.Tabs;
import forestry.apiculture.MaterialBeehive;
import forestry.core.config.Config;
import forestry.core.render.TextureManager;
import forestry.core.utils.StackUtils;
public class BlockBeehives extends BlockContainer {
public BlockBeehives() {
super(new MaterialBeehive(true));
setLightLevel(0.8f);
setHardness(1.0f);
setCreativeTab(Tabs.tabApiculture);
}
@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileSwarm();
}
@Override
public boolean canEntityDestroy(IBlockAccess world, int x, int y, int z, Entity entity) {
return false;
}
@Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) {
if (canHarvestBlock(player, world.getBlockMetadata(x, y, z))) {
// Handle TE'd beehives
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileSwarm) {
TileSwarm swarm = (TileSwarm) tile;
if (swarm.containsBees())
for (ItemStack beeStack : swarm.contained.getStacks())
if (beeStack != null)
StackUtils.dropItemStackAsEntity(beeStack, world, x, y, z);
}
}
return world.setBlockToAir(x, y, z);
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
// Handle legacy block
if (metadata == 0) {
ret.add(new ItemStack(this));
return ret;
}
ArrayList<IHiveDrop> dropList = BeeManager.hiveDrops[metadata - 1];
Collections.shuffle(dropList);
// Grab a princess
int tries = 0;
boolean hasPrincess = false;
while (tries <= 10 && !hasPrincess) {
tries++;
for (IHiveDrop drop : dropList)
if (world.rand.nextInt(100) < drop.getChance(world, x, y, z)) {
ret.add(drop.getPrincess(world, x, y, z, fortune));
hasPrincess = true;
break;
}
}
// Grab drones
for (IHiveDrop drop : dropList)
if (world.rand.nextInt(100) < drop.getChance(world, x, y, z)) {
ret.addAll(drop.getDrones(world, x, y, z, fortune));
break;
}
// Grab anything else on offer
for (IHiveDrop drop : dropList)
if (world.rand.nextInt(100) < drop.getChance(world, x, y, z)) {
ret.addAll(drop.getAdditional(world, x, y, z, fortune));
break;
}
return ret;
}
// / CREATIVE INVENTORY
@Override
public int damageDropped(int meta) {
return meta;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) {
itemList.add(new ItemStack(this, 1, 1));
itemList.add(new ItemStack(this, 1, 2));
itemList.add(new ItemStack(this, 1, 3));
itemList.add(new ItemStack(this, 1, 4));
if (Config.isDebug) {
itemList.add(new ItemStack(this, 1 ,5));
}
itemList.add(new ItemStack(this, 1, 6));
itemList.add(new ItemStack(this, 1, 7));
// Swarm hive not added
}
/* ICONS */
@SideOnly(Side.CLIENT)
private IIcon[] icons;
@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister register) {
icons = new IIcon[18];
for (int i = 1; i < 9; i++) {
icons[i * 2] = TextureManager.getInstance().registerTex(register, "beehives/beehive." + i + ".top");
icons[(i * 2) + 1] = TextureManager.getInstance().registerTex(register, "beehives/beehive." + i + ".side");
}
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int i, int j) {
if (i == 0 || i == 1) {
if (j * 2 < icons.length && icons[j * 2] != null)
return icons[j * 2];
else
return icons[2];
} else if (j * 2 + 1 < icons.length && icons[j * 2 + 1] != null)
return icons[j * 2 + 1];
else
return icons[3];
}
}
+419
View File
@@ -0,0 +1,419 @@
/*******************************************************************************
* 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.gadgets;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.BlockTorch;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import forestry.api.core.Tabs;
import forestry.core.ForestryClient;
import forestry.core.config.Defaults;
import forestry.core.render.TextureManager;
import forestry.core.utils.StackUtils;
public class BlockCandle extends BlockTorch {
private final ArrayList<Item> lightingItems = new ArrayList<Item>();
@SideOnly(Side.CLIENT)
private IIcon litStump;
@SideOnly(Side.CLIENT)
private IIcon litTip;
@SideOnly(Side.CLIENT)
private IIcon unlitStump;
@SideOnly(Side.CLIENT)
private IIcon unlitTip;
public BlockCandle() {
super();
this.setHardness(0.0F);
this.setStepSound(soundTypeWood);
setCreativeTab(Tabs.tabApiculture);
lightingItems.add(Items.flint_and_steel);
lightingItems.add(Items.flint);
lightingItems.add(Item.getItemFromBlock(Blocks.torch));
}
@Override
public boolean hasTileEntity(int metadata) {
return true;
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
return new TileCandle();
}
@Override
public int getRenderType() {
return ForestryClient.candleRenderId;
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister register) {
String fileBase = this.getUnlocalizedName().replace("tile.", "");
this.blockIcon = TextureManager.getInstance().registerTex(register, "stump");
this.litStump = TextureManager.getInstance().registerTex(register, fileBase + "StumpLit");
this.litTip = TextureManager.getInstance().registerTex(register, fileBase + "TipLit");
this.unlitStump = TextureManager.getInstance().registerTex(register, fileBase + "StumpUnlit");
this.unlitTip = TextureManager.getInstance().registerTex(register, fileBase + "TipUnlit");
}
@Override
public int getLightValue(IBlockAccess world, int x, int y, int z) {
int meta = world.getBlockMetadata(x, y, z);
return (isLit(meta))? 14 : 0;
}
/*@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
IIcon i = this.unlitStump;
if (this.isLit(world.getBlockMetadata(x, y, z))) {
i = this.litStump;
}
return i;
}*/
@SideOnly(Side.CLIENT)
public IIcon getTextureFromPassAndMeta(int meta, int pass) {
IIcon i = this.unlitStump;
if (pass == 0) {
if (isLit(meta)) {
i = this.litTip;
}
else {
i = this.unlitTip;
}
}
else {
if (isLit(meta)) {
i = this.litStump;
}
else {
i = this.unlitStump;
}
}
return i;
}
public int getColourFromItemStack(ItemStack stack) {
int colour = 0xffffff;
if (stack.hasTagCompound()) {
NBTTagCompound tag = stack.getTagCompound();
colour = (tag.getByte("red") << 16) | (tag.getByte("green") << 8) | tag.getByte("blue");
}
return colour;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) {
itemList.add(new ItemStack(this, 1, 0));
}
// Dye names correspond to colour values as below.
private static final String[] dyes = { "dyeWhite", "dyeOrange", "dyeMagenta", "dyeLightBlue",
"dyeYellow", "dyeLime", "dyePink", "dyeGray",
"dyeLightGray", "dyeCyan", "dyePurple", "dyeBlue",
"dyeBrown", "dyeGreen", "dyeRed", "dyeBlack" };
private static final int[][] colours = { { 255, 255, 255 } , { 219, 125, 62 } , { 255, 20, 255 } , { 107, 138, 201 } ,
{ 255, 255, 20 } , { 20, 255, 20 } , { 208, 132, 153 } , { 74, 74, 74 } ,
{ 154, 161, 161 } , { 20, 255, 255 } , { 126, 61, 181 } , { 20, 20, 255 } ,
{ 79, 50, 31 } , { 53, 70, 27 } , { 150, 52, 48 } , { 20, 20, 20 } };
public static final String colourTagName = "colour";
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int facing, float facingX, float facingY, float facingZ) {
boolean flag = false;
int meta = world.getBlockMetadata(x, y, z);
boolean toggleLitState = true;
ItemStack held = player.getCurrentEquippedItem();
if (!isLit(meta)) {
if (held == null || !lightingItems.contains(held.getItem())) {
toggleLitState = false;
}
else if (StackUtils.equals(this, held) && isLit(held)) {
toggleLitState = true;
}
}
if (held != null) {
// Ensure a TileEntity exists. May be able to remove this in future versions.
TileCandle te = (TileCandle)world.getTileEntity(x, y, z);
if (te == null) {
world.setTileEntity(x, y, z, this.createTileEntity(world, meta));
}
if (StackUtils.equals(this, held)) {
if (!isLit(held)) {
// Copy the colour of an unlit, coloured candle.
if (held.hasTagCompound() && held.getTagCompound().hasKey(colourTagName)) {
te.setColour(held.getTagCompound().getInteger(colourTagName));
}
else {
// Reset to white if item has no
te.setColour(0xffffff);
}
}
else {
toggleLitState = true;
}
flag = true;
}
else {
// Check for dye-able ness.
boolean matched = false;
for (int i = 0; i < dyes.length; ++i) {
for (ItemStack stack : OreDictionary.getOres(dyes[i])) {
if (OreDictionary.itemMatches(stack, held, true)) {
if (isLit(meta)) {
te.setColour(colours[i][0], colours[i][1], colours[i][2]);
}
else {
te.addColour(colours[i][0], colours[i][1], colours[i][2]);
}
world.markBlockForUpdate(x, y, z);
matched = true;
toggleLitState = false;
flag = true;
break;
}
}
if (matched) {
break;
}
}
}
}
if (toggleLitState) {
meta = this.toggleLitStatus(meta);
world.setBlockMetadataWithNotify(x, y, z, meta, Defaults.FLAG_BLOCK_SYNCH | Defaults.FLAG_BLOCK_UPDATE);
flag = true;
}
return flag;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
if (!world.isRemote) {
TileCandle tc = (TileCandle)world.getTileEntity(x, y, z);
int newMeta = isLit(meta) ? 1 : 0;
ItemStack stack = new ItemStack(this, 1, newMeta);
if (tc != null && tc.getColour() != 0xffffff) {
// When dropped, tag new item stack with colour. Unless it's white, then do no such thing for maximum stacking.
NBTTagCompound tag = new NBTTagCompound();
tag.setInteger(colourTagName, tc.getColour());
stack.setTagCompound(tag);
}
this.dropBlockAsItem(world, x, y, z, stack);
}
super.breakBlock(world, x, y, z, block, meta);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) {
TileCandle tc = (TileCandle)(world.getTileEntity(x, y, z));
tc.setColour(this.getColourValueFromItemStack(itemStack));
if (isLit(itemStack)) {
int meta = world.getBlockMetadata(x, y, z);
world.setBlockMetadataWithNotify(x, y, z, this.toggleLitStatus(meta), Defaults.FLAG_BLOCK_SYNCH | Defaults.FLAG_BLOCK_UPDATE);
}
}
@Override
public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) {
// Does nothing to prevent extra candles from falling.
}
@Override
public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) {
// Does nothing to prevent extra candles from falling.
}
@Override
protected boolean func_150109_e(World world, int x, int y, int z) {
// Slightly tweaked version of BlockTorch's version to account for TE nonsense.
if (!this.canPlaceBlockAt(world, x, y, z)) {
if (world.getBlock(x, y, z) == this) {
world.setBlockToAir(x, y, z);
}
return false;
}
else {
return true;
}
}
@Override
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random random) {
if (isLit(world.getBlockMetadata(x, y, z))) {
int l = world.getBlockMetadata(x, y, z) & 0x07;
double d0 = x + 0.5F;
double d1 = y + 0.7F;
double d2 = z + 0.5F;
double d3 = 0.2199999988079071D;
double d4 = 0.27000001072883606D;
if (l == 1)
{
world.spawnParticle("smoke", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
}
else if (l == 2)
{
world.spawnParticle("smoke", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
}
else if (l == 3)
{
world.spawnParticle("smoke", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
}
else if (l == 4)
{
world.spawnParticle("smoke", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
}
else
{
world.spawnParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D);
}
}
}
@Override
protected boolean func_150108_b(World par1World, int par2, int par3, int par4, Block block)
{
if (this.func_150109_e(par1World, par2, par3, par4))
{
int i1 = par1World.getBlockMetadata(par2, par3, par4) & 0x07;
boolean flag = false;
if (!par1World.isSideSolid(par2 - 1, par3, par4, ForgeDirection.EAST, true) && i1 == 1)
{
flag = true;
}
if (!par1World.isSideSolid(par2 + 1, par3, par4, ForgeDirection.WEST, true) && i1 == 2)
{
flag = true;
}
if (!par1World.isSideSolid(par2, par3, par4 - 1, ForgeDirection.SOUTH, true) && i1 == 3)
{
flag = true;
}
if (!par1World.isSideSolid(par2, par3, par4 + 1, ForgeDirection.NORTH, true) && i1 == 4)
{
flag = true;
}
if (!this.canPlaceTorchOn(par1World, par2, par3 - 1, par4) && i1 == 5)
{
flag = true;
}
if (flag)
{
this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
par1World.setBlockToAir(par2, par3, par4);
return true;
}
else
{
return false;
}
}
else
{
return true;
}
}
// Yes, function hiding. Go away.
public boolean canPlaceTorchOn(World par1World, int par2, int par3, int par4)
{
if (World.doesBlockHaveSolidTopSurface(par1World, par2, par3, par4))
{
return true;
}
else
{
Block block = par1World.getBlock(par2, par3, par4);
return block.canPlaceTorchOnTop(par1World, par2, par3, par4);
}
}
protected int getColourValueFromItemStack(ItemStack itemStack) {
int value = 0xffffff; // default to white.
if (itemStack.hasTagCompound()) {
NBTTagCompound tag = itemStack.getTagCompound();
if (tag.hasKey(colourTagName)) {
value = tag.getInteger(colourTagName);
}
}
return value;
}
public static boolean isLit(int meta) {
return (meta & 0x08) > 0;
}
public static boolean isLit(ItemStack itemStack) {
return itemStack.getItemDamage() > 0;
}
protected int toggleLitStatus(int meta) {
return meta ^ 0x08;
}
public void addItemToLightingList(Item item) {
if (item == null) throw new NullPointerException();
if (!this.lightingItems.contains(item)) {
this.lightingItems.add(item);
}
}
}
+83
View File
@@ -0,0 +1,83 @@
/*******************************************************************************
* 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.gadgets;
import java.util.List;
import java.util.Random;
import net.minecraft.block.BlockTorch;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.core.Tabs;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryBlock;
import forestry.core.render.TextureManager;
import forestry.core.utils.StackUtils;
public class BlockStump extends BlockTorch {
public BlockStump() {
super();
this.setHardness(0.0F);
this.setStepSound(soundTypeWood);
setCreativeTab(Tabs.tabApiculture);
}
@SideOnly(Side.CLIENT)
@Override
public void registerBlockIcons(IIconRegister register) {
this.blockIcon = TextureManager.getInstance().registerTex(register, this.getUnlocalizedName().replace("tile.", ""));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) {
itemList.add(new ItemStack(this, 1, 0));
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int facing, float facingX, float facingY, float facingZ) {
ItemStack held = player.getCurrentEquippedItem();
if (held != null &&
(held.getItem() == Items.flint_and_steel ||
held.getItem() == Items.flint ||
StackUtils.equals(Blocks.torch, held))) {
world.setBlock(x, y, z, ForestryBlock.candle, world.getBlockMetadata(x, y, z) | 0x08, Defaults.FLAG_BLOCK_SYNCH);
TileCandle tc = new TileCandle();
tc.setColour(0); // default to white
world.setTileEntity(x, y, z, tc);
return true;
}
return false;
}
@Override
@SideOnly(Side.CLIENT)
public int getRenderColor(int par1) {
return 0xee0000;
}
@Override
public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random) {
}
}
@@ -0,0 +1,119 @@
/*******************************************************************************
* 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.gadgets;
import java.util.HashSet;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.tileentity.TileEntity;
import forestry.api.apiculture.IAlvearyComponent;
import forestry.api.core.ITileStructure;
import forestry.core.config.ForestryBlock;
import forestry.core.gadgets.BlockStructure.EnumStructureState;
import forestry.core.gadgets.StructureLogic;
import forestry.core.utils.Schemata;
import forestry.core.utils.Schemata.EnumStructureBlock;
import forestry.core.utils.Vect;
public class StructureLogicAlveary extends StructureLogic {
/* CONSTANTS */
public static final String UID_ALVEARY = "alveary";
public static final Schemata SCHEMATA_ALVEARY = new Schemata("alveary3x3", 5, 6, 5, "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FAAAF",
"FAAAF", "FABAF", "FCCCF", "FFFFF", "FFFFF", "FAAAF", "FAAAF", "FBMBF", "FCCCF", "FFFFF", "FFFFF", "FAAAF", "FAAAF", "FABAF", "FCCCF", "FFFFF",
"FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF").setOffsets(-2, -3, -2);
public static HashSet<Block> slabBlocks = new HashSet<Block>();
static {
slabBlocks.add(Blocks.stone_slab);
slabBlocks.add(Blocks.wooden_slab);
slabBlocks.add(ForestryBlock.slabs1);
slabBlocks.add(ForestryBlock.slabs2);
slabBlocks.add(ForestryBlock.slabs3);
if (ForestryBlock.slabs4 != null)
slabBlocks.add(ForestryBlock.slabs4);
}
public StructureLogicAlveary(ITileStructure structure) {
super(UID_ALVEARY, structure);
schematas = new Schemata[] { SCHEMATA_ALVEARY };
metaOnValid.put(EnumStructureBlock.BLOCK_B, 1);
}
@Override
protected EnumStructureState determineMasterState(Schemata schemata, boolean rotate) {
Vect dimensions = schemata.getDimensions(rotate);
int offsetX = schemata.getxOffset();
int offsetZ = schemata.getzOffset();
if (rotate) {
offsetX = schemata.getzOffset();
offsetZ = schemata.getxOffset();
}
for (int i = 0; i < dimensions.x; i++)
for (int j = 0; j < schemata.getHeight(); j++)
for (int k = 0; k < dimensions.z; k++) {
int x = structureTile.xCoord + i + offsetX;
int y = structureTile.yCoord + j + schemata.getyOffset();
int z = structureTile.zCoord + k + offsetZ;
if (!structureTile.getWorldObj().blockExists(x, y, z))
return EnumStructureState.INDETERMINATE;
EnumStructureBlock required = schemata.getAt(i, j, k, rotate);
if (required == EnumStructureBlock.ANY)
continue;
TileEntity tile = structureTile.getWorldObj().getTileEntity(x, y, z);
Block block = structureTile.getWorldObj().getBlock(x, y, z);
switch (required) {
case AIR:
if (!block.isAir(structureTile.getWorldObj(), x, y, z))
return EnumStructureState.INVALID;
break;
case BLOCK_A:
if (tile == null || !(tile instanceof IAlvearyComponent))
return EnumStructureState.INVALID;
if (!((ITileStructure) tile).getTypeUID().equals(UID_ALVEARY))
return EnumStructureState.INVALID;
break;
case MASTER:
case BLOCK_B:
if (tile == null || !(tile instanceof TileAlvearyPlain))
return EnumStructureState.INVALID;
break;
case BLOCK_C:
if (!slabBlocks.contains(block))
return EnumStructureState.INVALID;
if ((structureTile.getWorldObj().getBlockMetadata(x, y, z) & 8) != 0)
return EnumStructureState.INVALID;
break;
case BLOCK_D:
if (block != Blocks.spruce_stairs)
return EnumStructureState.INVALID;
break;
case FOREIGN:
if (tile instanceof ITileStructure)
return EnumStructureState.INVALID;
break;
default:
return EnumStructureState.INDETERMINATE;
}
}
return EnumStructureState.VALID;
}
}
+265
View File
@@ -0,0 +1,265 @@
/*******************************************************************************
* 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.gadgets;
import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import buildcraft.api.gates.ITrigger;
import forestry.api.apiculture.IAlvearyComponent;
import forestry.api.apiculture.IBeeListener;
import forestry.api.apiculture.IBeeModifier;
import forestry.api.core.IStructureLogic;
import forestry.api.core.ITileStructure;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryBlock;
import forestry.core.gadgets.TileForestry;
import forestry.core.network.PacketPayload;
import forestry.core.proxy.Proxies;
import forestry.core.triggers.ForestryTrigger;
import forestry.core.utils.TileInventoryAdapter;
import forestry.core.utils.Utils;
public abstract class TileAlveary extends TileForestry implements IAlvearyComponent {
protected TileInventoryAdapter inventory;
protected final int componentBlockMeta;
public TileAlveary(int componentBlockMeta) {
this.structureLogic = new StructureLogicAlveary(this);
this.componentBlockMeta = componentBlockMeta;
}
/* UPDATING */
@Override
public void initialize() {
Block block = worldObj.getBlock(xCoord, yCoord, zCoord);
if (block != ForestryBlock.alveary) {
Proxies.log.info("Updating alveary block at %s/%s/%s.", xCoord, yCoord, zCoord);
worldObj.setBlock(xCoord, yCoord, zCoord, ForestryBlock.alveary, componentBlockMeta, Defaults.FLAG_BLOCK_SYNCH);
validate();
worldObj.setTileEntity(xCoord, yCoord, zCoord, this);
}
}
@Override
public void updateEntity() {
if (!Proxies.common.isSimulating(worldObj))
updateClientSide();
else {
if (!isInited) {
initialize();
isInited = true;
}
// Periodic validation if needed
if (worldObj.getTotalWorldTime() % 200 == 0 && (!isIntegratedIntoStructure() || isMaster()))
validateStructure();
updateServerSide();
}
}
protected void updateServerSide() {
}
protected void updateClientSide() {
}
/* TEXTURES */
public int getIcon(int side, int metadata) {
return BlockAlveary.PLAIN;
}
/* LOADING & SAVING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.isMaster = nbttagcompound.getBoolean("IsMaster");
this.masterX = nbttagcompound.getInteger("MasterX");
this.masterY = nbttagcompound.getInteger("MasterY");
this.masterZ = nbttagcompound.getInteger("MasterZ");
// Init for master state
if (isMaster)
makeMaster();
structureLogic.readFromNBT(nbttagcompound);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setBoolean("IsMaster", isMaster);
nbttagcompound.setInteger("MasterX", masterX);
nbttagcompound.setInteger("MasterY", masterY);
nbttagcompound.setInteger("MasterZ", masterZ);
structureLogic.writeToNBT(nbttagcompound);
}
protected void createInventory() {}
@Override
public void fromPacketPayload(PacketPayload payload) {
}
@Override
public PacketPayload getPacketPayload() {
return null;
}
/* ITILESTRUCTURE */
IStructureLogic structureLogic;
private boolean isMaster;
protected int masterX, masterZ;
protected int masterY = -99;
@Override
public String getTypeUID() {
return structureLogic.getTypeUID();
}
@Override
public void validateStructure() {
structureLogic.validateStructure();
}
@Override
public void makeMaster() {
setCentralTE(null);
isMaster = true;
if (inventory == null)
createInventory();
}
@Override
public void onStructureReset() {
setCentralTE(null);
if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1)
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 0);
isMaster = false;
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
public ITileStructure getCentralTE() {
if (!isIntegratedIntoStructure())
return null;
if (!isMaster()) {
TileEntity tile = worldObj.getTileEntity(masterX, masterY, masterZ);
if (tile instanceof ITileStructure) {
ITileStructure master = (ITileStructure) worldObj.getTileEntity(masterX, masterY, masterZ);
if (master.isMaster())
return master;
else
return null;
} else
return null;
} else
return this;
}
private boolean isSameTile(TileEntity tile) {
return tile.xCoord == xCoord && tile.yCoord == yCoord && tile.zCoord == zCoord;
}
@Override
public void setCentralTE(TileEntity tile) {
if (tile == null || tile == this || isSameTile(tile)) {
this.masterX = this.masterZ = 0;
this.masterY = -99;
return;
}
this.isMaster = false;
this.masterX = tile.xCoord;
this.masterY = tile.yCoord;
this.masterZ = tile.zCoord;
}
@Override
public boolean isMaster() {
return isMaster;
}
protected boolean hasMaster() {
return masterY >= 0;
}
@Override
public boolean isIntegratedIntoStructure() {
return isMaster || masterY >= 0;
}
@Override
public IInventory getInventory() {
return inventory;
}
/* IALVEARY COMPONENT */
@Override
public boolean hasFunction() {
return false;
}
@Override
public void addTemperatureChange(float change, float boundaryDown, float boundaryUp) {
}
@Override
public void addHumidityChange(float change, float boundaryDown, float boundaryUp) {
}
@Override
public void registerBeeModifier(IBeeModifier modifier) {
}
@Override
public void removeBeeModifier(IBeeModifier modifier) {
}
@Override
public void registerBeeListener(IBeeListener event) {
}
@Override
public void removeBeeListener(IBeeListener event) {
}
// / ITRIGGERPROVIDER
@Override
public LinkedList<ITrigger> getCustomTriggers() {
LinkedList<ITrigger> res = new LinkedList<ITrigger>();
res.add(ForestryTrigger.missingQueen);
res.add(ForestryTrigger.missingDrone);
return res;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return Utils.isUseableByPlayer(player, this, worldObj, xCoord, yCoord, zCoord);
}
}
@@ -0,0 +1,160 @@
/*******************************************************************************
* 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.gadgets;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import forestry.api.apiculture.IAlvearyComponent;
import forestry.core.network.PacketPayload;
public abstract class TileAlvearyClimatiser extends TileAlveary implements IPowerReceptor {
public static class ClimateControl {
final float changePerTransfer;
final float boundaryUp;
final float boundaryDown;
public ClimateControl(float changePerTransfer, float boundaryDown, float boundaryUp) {
this.changePerTransfer = changePerTransfer;
this.boundaryDown = boundaryDown;
this.boundaryUp = boundaryUp;
}
}
PowerHandler powerProvider;
ClimateControl climateControl;
private int transferTime = 0;
private int animationDelay = 0;
private final int textureOff;
private final int textureOn;
public TileAlvearyClimatiser(ClimateControl control, int textureOff, int textureOn, int componentBlockMeta) {
super(componentBlockMeta);
this.climateControl = control;
powerProvider = new PowerHandler(this, Type.MACHINE);
powerProvider.configure(10, 100, 25, 200);
this.textureOff = textureOff;
this.textureOn = textureOn;
}
@Override
public void openGui(EntityPlayer player) {
}
/* UPDATING */
@Override
protected void updateServerSide() {
super.updateServerSide();
// BC Power
if (powerProvider != null) {
powerProvider.update();
}
if (!this.hasMaster())
return;
if (transferTime > 0) {
transferTime--;
IAlvearyComponent component = (IAlvearyComponent) this.getCentralTE();
if (component != null)
component.addTemperatureChange(climateControl.changePerTransfer, climateControl.boundaryDown, climateControl.boundaryUp);
}
if (animationDelay > 0) {
animationDelay--;
if (animationDelay <= 0)
sendNetworkUpdate();
}
}
@Override
public boolean hasFunction() {
return true;
}
/* TEXTURES */
@Override
public int getIcon(int side, int metadata) {
if (animationDelay > 0)
return textureOn;
else
return textureOff;
}
/* IPOWERRECEPTOR */
@Override
public void doWork(PowerHandler workProvider) {
if (!this.hasMaster())
return;
if (powerProvider.useEnergy(powerProvider.getActivationEnergy(), powerProvider.getEnergyStored(), false) < powerProvider.getActivationEnergy())
return;
transferTime = (int) Math.round(powerProvider.useEnergy(powerProvider.getActivationEnergy(), powerProvider.getEnergyStored(), true));
if (animationDelay <= 0) {
animationDelay = 100;
sendNetworkUpdate();
} else
animationDelay = 100;
}
@Override
public PowerReceiver getPowerReceiver(ForgeDirection side) {
return powerProvider.getPowerReceiver();
}
/* LOADING & SAVING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
powerProvider.readFromNBT(nbttagcompound);
transferTime = nbttagcompound.getInteger("Heating");
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
powerProvider.writeToNBT(nbttagcompound);
nbttagcompound.setInteger("Heating", transferTime);
}
@Override
public String getInventoryName() {
return "tile.alveary.climatiser";
}
/* NETWORK */
@Override
public void fromPacketPayload(PacketPayload payload) {
short delay = payload.shortPayload[0];
if (animationDelay != delay) {
animationDelay = delay;
worldObj.func_147479_m(xCoord, yCoord, zCoord);
}
}
@Override
public PacketPayload getPacketPayload() {
PacketPayload payload = new PacketPayload(0, 1);
payload.shortPayload[0] = (short) animationDelay;
return payload;
}
}
@@ -0,0 +1,22 @@
/*******************************************************************************
* 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.gadgets;
public class TileAlvearyFan extends TileAlvearyClimatiser {
/* CONSTANTS */
public static final int BLOCK_META = 3;
public TileAlvearyFan() {
super(new ClimateControl(-0.01f, 0.05f, 2.5f), BlockAlveary.TX_71_FNOF, BlockAlveary.TX_72_FNON, BLOCK_META);
}
}
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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.gadgets;
public class TileAlvearyHeater extends TileAlvearyClimatiser {
public static final int TEXTURE_OFF = 57;
public static final int TEXTURE_ON = 58;
/* CONSTANTS */
public static final int BLOCK_META = 4;
public TileAlvearyHeater() {
super(new ClimateControl(0.01f, 0.0f, 2.5f), BlockAlveary.TX_57_HTOF, BlockAlveary.TX_58_HTON, BLOCK_META);
}
}
@@ -0,0 +1,297 @@
/*******************************************************************************
* 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.gadgets;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.apiculture.IAlvearyComponent;
import forestry.api.core.ForestryAPI;
import forestry.core.config.Defaults;
import forestry.core.interfaces.ILiquidTankContainer;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.utils.ForestryTank;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.LiquidHelper;
import forestry.core.utils.StackUtils;
public class TileAlvearyHygroregulator extends TileAlveary implements IInventory, ILiquidTankContainer {
/* CONSTANTS */
public static final int BLOCK_META = 5;
/* RECIPE MANAGMENT */
private static class HygroregulatorRecipe {
public final FluidStack liquid;
public final int transferTime;
public final float humidChange;
public final float tempChange;
public HygroregulatorRecipe(FluidStack liquid, int transferTime, float humidChange, float tempChange) {
this.liquid = liquid;
this.transferTime = transferTime;
this.humidChange = humidChange;
this.tempChange = tempChange;
}
}
private final HygroregulatorRecipe[] recipes;
/* MEMBERS */
InventoryAdapter canInventory = new InventoryAdapter(1, "CanInv");
private ForestryTank liquidTank = new ForestryTank(Defaults.PROCESSOR_TANK_CAPACITY);
private HygroregulatorRecipe currentRecipe;
private int transferTime;
public TileAlvearyHygroregulator() {
super(BLOCK_META);
recipes = new HygroregulatorRecipe[] { new HygroregulatorRecipe(new FluidStack(LiquidHelper.getFluid(Defaults.LIQUID_WATER), 1), 1, 0.01f, -0.005f),
new HygroregulatorRecipe(new FluidStack(LiquidHelper.getFluid(Defaults.LIQUID_LAVA), 1), 10, -0.01f, +0.005f),
new HygroregulatorRecipe(new FluidStack(LiquidHelper.getFluid(Defaults.LIQUID_ICE), 1), 10, 0.02f, -0.01f) };
}
@Override
public void openGui(EntityPlayer player) {
player.openGui(ForestryAPI.instance, GuiId.HygroregulatorGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
}
@Override
public String getInventoryName() {
return "tile.alveary.5";
}
/* UPDATING */
private HygroregulatorRecipe getRecipe(FluidStack liquid) {
HygroregulatorRecipe recipe = null;
for (HygroregulatorRecipe rec : recipes)
if (rec.liquid.isFluidEqual(liquid)) {
recipe = rec;
break;
}
return recipe;
}
@Override
protected void updateServerSide() {
super.updateServerSide();
if (transferTime <= 0 && liquidTank.getFluidAmount() > 0) {
currentRecipe = getRecipe(liquidTank.getFluid());
if (currentRecipe != null) {
liquidTank.drain(currentRecipe.liquid.amount, true);
transferTime = currentRecipe.transferTime;
}
}
if (transferTime > 0) {
transferTime--;
if (currentRecipe != null) {
IAlvearyComponent component = (IAlvearyComponent) this.getCentralTE();
if (component != null) {
component.addHumidityChange(currentRecipe.humidChange, 0.0f, 1.0f);
component.addTemperatureChange(currentRecipe.tempChange, 0.0f, 2.0f);
}
} else
transferTime = 0;
}
if (worldObj.getTotalWorldTime() % 20 * 10 != 0)
return;
// Check if we have suitable items waiting in the item slot
if (canInventory.getStackInSlot(0) != null) {
FluidContainerData container = LiquidHelper.getLiquidContainer(canInventory.getStackInSlot(0));
if (container != null &&
(container.fluid.getFluid() == FluidRegistry.WATER || container.fluid.getFluid() == FluidRegistry.LAVA)) {
canInventory.setInventorySlotContents(0, StackUtils.replenishByContainer(this, canInventory.getStackInSlot(0), container, liquidTank));
if (canInventory.getStackInSlot(0).stackSize <= 0)
canInventory.setInventorySlotContents(0, null);
}
}
}
@Override
public boolean hasFunction() {
return true;
}
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
canInventory.readFromNBT(nbttagcompound);
liquidTank = new ForestryTank(Defaults.PROCESSOR_TANK_CAPACITY);
if (nbttagcompound.hasKey("LiquidTank"))
liquidTank.readFromNBT(nbttagcompound.getCompoundTag("LiquidTank"));
transferTime = nbttagcompound.getInteger("TransferTime");
if (nbttagcompound.hasKey("CurrentLiquid")) {
FluidStack liquid = FluidStack.loadFluidStackFromNBT(nbttagcompound.getCompoundTag("CurrentLiquid"));
currentRecipe = getRecipe(liquid);
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
canInventory.writeToNBT(nbttagcompound);
NBTTagCompound NBTresourceSlot = new NBTTagCompound();
liquidTank.writeToNBT(NBTresourceSlot);
nbttagcompound.setTag("LiquidTank", NBTresourceSlot);
nbttagcompound.setInteger("TransferTime", transferTime);
if (currentRecipe != null) {
NBTTagCompound subcompound = new NBTTagCompound();
currentRecipe.liquid.writeToNBT(subcompound);
nbttagcompound.setTag("CurrentLiquid", subcompound);
}
}
/* TEXTURES */
@Override
public int getIcon(int side, int metadata) {
return BlockAlveary.TX_73_VLVE;
}
@Override
public IInventory getInventory() {
return canInventory;
}
/* IINVENTORY */
@Override
public int getSizeInventory() {
if (canInventory != null)
return canInventory.getSizeInventory();
else
return 0;
}
@Override
public ItemStack getStackInSlot(int slotIndex) {
if (canInventory != null)
return canInventory.getStackInSlot(slotIndex);
else
return null;
}
@Override
public ItemStack decrStackSize(int slotIndex, int amount) {
if (canInventory != null)
return canInventory.decrStackSize(slotIndex, amount);
else
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slotIndex) {
if (canInventory != null)
return canInventory.getStackInSlotOnClosing(slotIndex);
else
return null;
}
@Override
public void setInventorySlotContents(int slotIndex, ItemStack itemstack) {
// Client side handling for container synch
if (canInventory == null && !Proxies.common.isSimulating(worldObj))
createInventory();
if (canInventory != null)
canInventory.setInventorySlotContents(slotIndex, itemstack);
}
@Override
public int getInventoryStackLimit() {
if (canInventory != null)
return canInventory.getInventoryStackLimit();
else
return 0;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return super.isUseableByPlayer(player);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean hasCustomInventoryName() {
return super.hasCustomInventoryName();
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
return super.isItemValidForSlot(slotIndex, itemstack);
}
/* ILIQUIDTANKCONTAINER */
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return liquidTank.fill(resource, doFill);
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
return liquidTank.drain(maxDrain, doDrain);
}
@Override
public ForestryTank[] getTanks() {
return new ForestryTank[] { liquidTank };
}
/* SMP GUI */
public void getGUINetworkData(int i, int j) {
}
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
}
}
@@ -0,0 +1,843 @@
/*******************************************************************************
* 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.gadgets;
import java.util.LinkedHashSet;
import java.util.Set;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.util.ForgeDirection;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeListener;
import forestry.api.apiculture.IBeeModifier;
import forestry.api.apiculture.IBeekeepingLogic;
import forestry.api.core.*;
import forestry.api.genetics.IIndividual;
import forestry.apiculture.gui.ContainerAlveary;
import forestry.core.EnumErrorCode;
import forestry.core.config.Config;
import forestry.core.config.ForestryItem;
import forestry.core.interfaces.IClimatised;
import forestry.core.interfaces.IErrorSource;
import forestry.core.interfaces.IHintSource;
import forestry.core.network.GuiId;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketInventoryStack;
import forestry.core.proxy.Proxies;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.TileInventoryAdapter;
import forestry.plugins.PluginApiculture;
public class TileAlvearyPlain extends TileAlveary implements ISidedInventory, ISpecialInventory, IBeeHousing, IClimatised, IHintSource {
// / CONSTANTS
public static final int SLOT_QUEEN = 0;
public static final int SLOT_DRONE = 1;
public static final int SLOT_PRODUCT_1 = 2;
public static final int SLOT_PRODUCTION_COUNT = 7;
// / MEMBERS
protected IBeekeepingLogic beekeepingLogic;
protected int biomeId;
protected float temperature;
protected float humidity;
protected float tempChange = 0.0f;
protected float humidChange = 0.0f;
private int displayHealthMax = 0;
private int displayHealth = 0;
public TileAlvearyPlain() {
super(0);
}
@Override
public void openGui(EntityPlayer player) {
if (isMaster())
player.openGui(ForestryAPI.instance, GuiId.AlvearyGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
else if (this.hasMaster())
player.openGui(ForestryAPI.instance, GuiId.AlvearyGUI.ordinal(), worldObj, masterX, masterY, masterZ);
}
/* LOADING & SAVING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
this.tempChange = nbttagcompound.getFloat("TempChange");
this.humidChange = nbttagcompound.getFloat("HumidChange");
if (inventory != null)
inventory.readFromNBT(nbttagcompound);
if (beekeepingLogic != null)
beekeepingLogic.readFromNBT(nbttagcompound);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setFloat("TempChange", tempChange);
nbttagcompound.setFloat("HumidChange", humidChange);
if (inventory != null)
inventory.writeToNBT(nbttagcompound);
if (beekeepingLogic != null)
beekeepingLogic.writeToNBT(nbttagcompound);
}
/* UPDATING */
@Override
public void initialize() {
super.initialize();
BiomeGenBase biome = worldObj.getBiomeGenForCoordsBody(xCoord, zCoord);
this.biomeId = biome.biomeID;
this.temperature = biome.temperature;
this.humidity = biome.rainfall;
setErrorState(EnumErrorCode.OK);
}
@Override
protected void updateServerSide() {
if (beekeepingLogic == null)
return;
if (!isMaster())
return;
beekeepingLogic.update();
// Equalize humidity and temperature
equalizeTemperature();
equalizeHumidity();
IBee queen = beekeepingLogic.getQueen();
if (queen == null)
return;
// Add swarm effects
if (worldObj.getTotalWorldTime() % 200 * 10 == 0)
onQueenChange(inventory.getStackInSlot(SLOT_QUEEN));
if (getErrorState() == EnumErrorCode.OK)
queen.doFX(beekeepingLogic.getEffectData(), this);
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 50 == 0) {
float f = xCoord + 0.5F;
float f1 = yCoord + 0.0F + (worldObj.rand.nextFloat() * 6F) / 16F;
float f2 = zCoord + 0.5F;
float f3 = 0.52F;
float f4 = worldObj.rand.nextFloat() * 0.6F - 0.3F;
Proxies.common.addEntitySwarmFX(worldObj, (f - f3), f1, (f2 + f4), 0F, 0F, 0F);
Proxies.common.addEntitySwarmFX(worldObj, (f + f3), f1, (f2 + f4), 0F, 0F, 0F);
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 - f3), 0F, 0F, 0F);
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 + f3), 0F, 0F, 0F);
}
}
@Override
protected void updateClientSide() {
if (!isMaster())
return;
if (inventory == null)
return;
// / Multiplayer FX
if (PluginApiculture.beeInterface.isMated(inventory.getStackInSlot(SLOT_QUEEN)))
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 == 0) {
IBee displayQueen = PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN));
displayQueen.doFX(beekeepingLogic.getEffectData(), this);
}
return;
}
private void equalizeTemperature() {
if (tempChange == 0)
return;
tempChange -= 0.05f * tempChange;
if (tempChange <= 0.001f && tempChange >= -0.001f)
tempChange = 0;
}
private void equalizeHumidity() {
if (humidChange == 0)
return;
humidChange -= 0.05f * humidChange;
if (humidChange <= 0.001f && humidChange >= 0.001f)
humidChange = 0;
}
/* STATE INFORMATION */
private int getHealthDisplay() {
if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null)
return 0;
if (PluginApiculture.beeInterface.isMated(inventory.getStackInSlot(SLOT_QUEEN)))
return PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getHealth();
else if (!PluginApiculture.beeInterface.isDrone(inventory.getStackInSlot(SLOT_QUEEN)))
return displayHealth;
else
return 0;
}
private int getMaxHealthDisplay() {
if (inventory == null || inventory.getStackInSlot(SLOT_QUEEN) == null)
return 0;
if (PluginApiculture.beeInterface.isMated(inventory.getStackInSlot(SLOT_QUEEN)))
return PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getMaxHealth();
else if (!PluginApiculture.beeInterface.isDrone(inventory.getStackInSlot(SLOT_QUEEN)))
return displayHealthMax;
else
return 0;
}
public int getHealthScaled(int i) {
if (getMaxHealthDisplay() == 0)
return 0;
return (getHealthDisplay() * i) / getMaxHealthDisplay();
}
@Override
public boolean allowsInteraction(EntityPlayer player) {
if (!super.allowsInteraction(player))
return false;
return this.isIntegratedIntoStructure();
}
/* STRUCTURE MANAGMENT */
@Override
protected void createInventory() {
this.inventory = new TileInventoryAdapter(this, 9, "Items");
}
@Override
public void makeMaster() {
super.makeMaster();
if (beekeepingLogic == null)
this.beekeepingLogic = PluginApiculture.beeInterface.createBeekeepingLogic(this);
}
@Override
public void onStructureReset() {
super.onStructureReset();
modifiers.clear();
eventHandlers.clear();
}
/* IALVEARYCOMPONENT */
private final Set<IBeeModifier> modifiers = new LinkedHashSet<IBeeModifier>();
private final Set<IBeeListener> eventHandlers = new LinkedHashSet<IBeeListener>();
@Override
public void registerBeeModifier(IBeeModifier modifier) {
modifiers.add(modifier);
}
@Override
public void removeBeeModifier(IBeeModifier modifier) {
modifiers.remove(modifier);
}
@Override
public void registerBeeListener(IBeeListener modifier) {
eventHandlers.add(modifier);
}
@Override
public void removeBeeListener(IBeeListener modifier) {
eventHandlers.remove(modifier);
}
@Override
public void addTemperatureChange(float change, float boundaryDown, float boundaryUp) {
tempChange = Math.min(boundaryUp - temperature, Math.max(boundaryDown - temperature, tempChange + change));
}
@Override
public void addHumidityChange(float change, float boundaryDown, float boundaryUp) {
humidChange = Math.min(boundaryUp - humidity, Math.max(boundaryDown - humidity, humidChange + change));
}
/* IBEEHOUSING */
@Override
public int getXCoord() {
return xCoord;
}
@Override
public int getYCoord() {
return yCoord;
}
@Override
public int getZCoord() {
return zCoord;
}
@Override
public ItemStack getQueen() {
return getStackInSlot(SLOT_QUEEN);
}
@Override
public ItemStack getDrone() {
return getStackInSlot(SLOT_DRONE);
}
@Override
public void setQueen(ItemStack itemstack) {
setInventorySlotContents(SLOT_QUEEN, itemstack);
}
@Override
public void setDrone(ItemStack itemstack) {
setInventorySlotContents(SLOT_DRONE, itemstack);
}
@Override
public int getBiomeId() {
return this.biomeId;
}
@Override
public EnumTemperature getTemperature() {
if (EnumTemperature.isBiomeHellish(biomeId) && tempChange >= 0)
return EnumTemperature.HELLISH;
return EnumTemperature.getFromValue(getExactTemperature());
}
@Override
public EnumHumidity getHumidity() {
return EnumHumidity.getFromValue(getExactHumidity());
}
@Override
public float getTerritoryModifier(IBeeGenome genome, float currentModifier) {
float mod = 2.0f;
for (IBeeModifier modifier : modifiers) {
mod *= modifier.getTerritoryModifier(genome, mod);
}
return mod;
}
@Override
public float getProductionModifier(IBeeGenome genome, float currentModifier) {
float mod = 1.0f;
for (IBeeModifier modifier : modifiers) {
mod *= modifier.getProductionModifier(genome, mod);
}
return mod;
}
@Override
public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
float mod = 1.0f;
for (IBeeModifier modifier : modifiers) {
mod *= modifier.getMutationModifier(genome, mate, mod);
}
return mod;
}
@Override
public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
float mod = 1.0f;
for (IBeeModifier modifier : modifiers) {
mod *= modifier.getLifespanModifier(genome, mate, mod);
}
return mod;
}
@Override
public float getFloweringModifier(IBeeGenome genome, float currentModifier) {
float mod = 1.0f;
for (IBeeModifier modifier : modifiers) {
mod *= modifier.getFloweringModifier(genome, mod);
}
return mod;
}
@Override
public float getGeneticDecay(IBeeGenome genome, float currentModifier) {
float mod = 1.0f;
for (IBeeModifier modifier : modifiers) {
mod *= modifier.getGeneticDecay(genome, mod);
}
return mod;
}
@Override
public World getWorld() {
return worldObj;
}
@Override
public void setErrorState(int state) {
setErrorState(EnumErrorCode.values()[state]);
}
@Override
public int getErrorOrdinal() {
return getErrorState().ordinal();
}
@Override
public boolean canBreed() {
return true;
}
@Override
public boolean addProduct(ItemStack product, boolean all) {
if (inventory == null)
return false;
return inventory.tryAddStack(product, SLOT_PRODUCT_1, inventory.getSizeInventory() - SLOT_PRODUCT_1, all);
}
@Override
public void wearOutEquipment(int amount) {
for (IBeeListener eventHandler : eventHandlers) {
eventHandler.wearOutEquipment(amount);
}
}
@Override
public void onQueenChange(ItemStack queenStack) {
if (!Proxies.common.isSimulating(worldObj))
return;
Proxies.net.sendNetworkPacket(new PacketInventoryStack(PacketIds.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack), xCoord, yCoord,
zCoord);
for (IBeeListener eventHandler : eventHandlers) {
eventHandler.onQueenChange(queenStack);
}
}
@Override
public void onQueenDeath(IBee queen) {
for (IBeeListener eventHandler : eventHandlers) {
eventHandler.onQueenDeath(queen);
}
}
@Override
public void onPostQueenDeath(IBee queen) {
for (IBeeListener eventHandler : eventHandlers) {
eventHandler.onPostQueenDeath(queen);
}
}
@Override
public boolean onPollenRetrieved(IBee queen, IIndividual pollen, boolean isHandled) {
for (IBeeListener eventHandler : eventHandlers) {
if (eventHandler.onPollenRetrieved(queen, pollen, isHandled))
isHandled = true;
}
return isHandled;
}
@Override
public boolean onEggLaid(IBee queen) {
for (IBeeListener eventHandler : eventHandlers) {
if (eventHandler.onEggLaid(queen))
return true;
}
return false;
}
@Override
public boolean isSealed() {
for (IBeeModifier modifier : modifiers) {
if (modifier.isSealed())
return true;
}
return false;
}
@Override
public boolean isSelfLighted() {
for (IBeeModifier modifier : modifiers) {
if (modifier.isSelfLighted())
return true;
}
return false;
}
@Override
public boolean isSunlightSimulated() {
for (IBeeModifier modifier : modifiers) {
if (modifier.isSunlightSimulated())
return true;
}
return false;
}
@Override
public boolean isHellish() {
for (IBeeModifier modifier : modifiers) {
if (modifier.isHellish())
return true;
}
return false;
}
/* IINVENTORY */
@Override
public InventoryAdapter getInternalInventory() {
return (InventoryAdapter) getStructureInventory();
}
private IInventory getStructureInventory() {
if (inventory != null) {
if (isMaster() || !Proxies.common.isSimulating(worldObj))
return inventory;
} else if (hasMaster()) {
ITileStructure central = getCentralTE();
if (central != null)
return central.getInventory();
}
return null;
}
@Override
public int getSizeInventory() {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getSizeInventory();
else
return 0;
}
@Override
public ItemStack getStackInSlot(int slotIndex) {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getStackInSlot(slotIndex);
else
return null;
}
@Override
public ItemStack decrStackSize(int slotIndex, int amount) {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.decrStackSize(slotIndex, amount);
else
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slotIndex) {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getStackInSlotOnClosing(slotIndex);
else
return null;
}
@Override
public void setInventorySlotContents(int slotIndex, ItemStack itemstack) {
// Client side handling for container synch
if (inventory == null && !Proxies.common.isSimulating(worldObj))
createInventory();
IInventory inv = getStructureInventory();
if (inv != null)
inv.setInventorySlotContents(slotIndex, itemstack);
}
@Override
public String getInventoryName() {
return "alveary.0";
}
@Override
public int getInventoryStackLimit() {
IInventory inv = getStructureInventory();
if (inv != null)
return inv.getInventoryStackLimit();
else
return 0;
}
@Override
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
if (!super.canTakeStackFromSide(slotIndex, itemstack, side))
return false;
if (slotIndex != SLOT_QUEEN && slotIndex != SLOT_DRONE)
return true;
return false;
}
@Override
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
if (!super.canPutStackFromSide(slotIndex, itemstack, side))
return false;
if (slotIndex == SLOT_QUEEN && PluginApiculture.beeInterface.isMember(itemstack)
&& !PluginApiculture.beeInterface.isDrone(itemstack))
return true;
if (slotIndex == SLOT_DRONE && PluginApiculture.beeInterface.isDrone(itemstack))
return true;
return false;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return super.isUseableByPlayer(player);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean hasCustomInventoryName() {
return super.hasCustomInventoryName();
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
return super.isItemValidForSlot(slotIndex, itemstack);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
return super.canInsertItem(i, itemstack, j);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
return super.canExtractItem(i, itemstack, j);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public int[] getAccessibleSlotsFromSide(int side) {
return super.getAccessibleSlotsFromSide(side);
}
/* ISPECIALINVENTORY */
@Override
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
IInventory inv = getStructureInventory();
if (inv == null)
return 0;
// Princesses && Queens
if (ForestryItem.beePrincessGE.isItemEqual(stack) || ForestryItem.beeQueenGE.isItemEqual(stack))
if (inv.getStackInSlot(SLOT_QUEEN) == null) {
if (doAdd) {
inv.setInventorySlotContents(SLOT_QUEEN, stack.copy());
inv.getStackInSlot(SLOT_QUEEN).stackSize = 1;
}
return 1;
}
// Drones
if (ForestryItem.beeDroneGE.isItemEqual(stack)) {
ItemStack droneStack = inv.getStackInSlot(SLOT_DRONE);
if (droneStack == null) {
if (doAdd)
inv.setInventorySlotContents(SLOT_DRONE, stack.copy());
return stack.stackSize;
} else {
if (!droneStack.isItemEqual(stack))
return 0;
if (!ItemStack.areItemStackTagsEqual(droneStack, stack))
return 0;
int space = droneStack.getMaxStackSize() - droneStack.stackSize;
if (space <= 0)
return 0;
int added = space > stack.stackSize ? stack.stackSize : space;
if (doAdd)
droneStack.stackSize += added;
return added;
}
}
return 0;
}
@Override
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
IInventory inv = getStructureInventory();
if (inv == null)
return new ItemStack[0];
ItemStack product = null;
for (int i = SLOT_PRODUCT_1; i < inv.getSizeInventory(); i++) {
if (inv.getStackInSlot(i) == null)
continue;
ItemStack stack = inv.getStackInSlot(i);
if (doRemove)
product = inv.decrStackSize(i, 1);
else {
product = stack.copy();
product.stackSize = 1;
}
break;
}
return new ItemStack[] { product };
}
/* SMP GUI */
public void getGUINetworkData(int i, int j) {
switch (i) {
case 0:
displayHealth = j;
break;
case 1:
displayHealthMax = j;
break;
case 2:
this.temperature = (float) j / 100;
break;
case 3:
this.humidity = (float) j / 100;
break;
case 4:
this.tempChange = (float) j / 100;
break;
case 5:
this.humidChange = (float) j / 100;
break;
case 6:
this.biomeId = j;
break;
}
}
public void sendGUINetworkData(ContainerAlveary container, ICrafting iCrafting) {
if (beekeepingLogic == null)
return;
iCrafting.sendProgressBarUpdate(container, 0, beekeepingLogic.getBreedingTime());
iCrafting.sendProgressBarUpdate(container, 1, beekeepingLogic.getTotalBreedingTime());
iCrafting.sendProgressBarUpdate(container, 2, Math.round(temperature * 100));
iCrafting.sendProgressBarUpdate(container, 3, Math.round(humidity * 100));
iCrafting.sendProgressBarUpdate(container, 4, Math.round(tempChange * 100));
iCrafting.sendProgressBarUpdate(container, 5, Math.round(humidChange * 100));
iCrafting.sendProgressBarUpdate(container, 6, biomeId);
}
/* IERRORSOURCE */
@Override
public EnumErrorCode getErrorState() {
if (hasMaster()) {
ITileStructure tile = this.getCentralTE();
if (tile != null)
return ((IErrorSource) tile).getErrorState();
}
return errorState;
}
/* ICLIMATISED */
@Override
public boolean isClimatized() {
return true;
}
@Override
public float getExactTemperature() {
return this.temperature + this.tempChange;
}
@Override
public float getExactHumidity() {
return this.humidity + this.humidChange;
}
/* IHINTSOURCE */
@Override
public boolean hasHints() {
return Config.hints.get("alveary").length > 0;
}
@Override
public String[] getHints() {
return Config.hints.get("alveary");
}
/* IOWNABLE */
@Override
public boolean isOwnable() {
return true;
}
/* IHousing */
@Override
public GameProfile getOwnerName() {
return this.getOwnerProfile();
}
}
@@ -0,0 +1,182 @@
/*******************************************************************************
* 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.gadgets;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import forestry.api.apiculture.IAlvearyComponent;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeListener;
import forestry.api.arboriculture.EnumGermlingType;
import forestry.api.core.ForestryAPI;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IIndividual;
import forestry.core.interfaces.ICrafter;
import forestry.core.network.GuiId;
import forestry.core.utils.InventoryAdapter;
public class TileAlvearySieve extends TileAlveary implements ICrafter, IBeeListener {
/* CONSTANTS */
public static final int BLOCK_META = 7;
public static final int SLOT_POLLEN_1 = 0;
public static final int SLOTS_POLLEN_COUNT = 4;
public static final int SLOT_SIEVE = 4;
InventoryAdapter inventory = new InventoryAdapter(5, "Items", 1);
public TileAlvearySieve() {
super(BLOCK_META);
}
@Override
public void openGui(EntityPlayer player) {
player.openGui(ForestryAPI.instance, GuiId.AlvearySieveGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
}
@Override
public String getInventoryName() {
return "tile.alveary.7";
}
@Override
public boolean hasFunction() {
return true;
}
/* UPDATING */
@Override
public void initialize() {
super.initialize();
if(!hasMaster() || !isIntegratedIntoStructure())
return;
((IAlvearyComponent)getCentralTE()).registerBeeListener(this);
}
@Override
protected void updateServerSide() {
super.updateServerSide();
if(worldObj.getTotalWorldTime() % 200 != 0)
return;
if(!hasMaster() || !isIntegratedIntoStructure())
return;
((IAlvearyComponent)getCentralTE()).registerBeeListener(this);
}
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
inventory.readFromNBT(nbttagcompound);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
inventory.writeToNBT(nbttagcompound);
}
/* TEXTURES & INTERNAL */
@Override
public int getIcon(int side, int metadata) {
if(side == 0 || side == 1)
return BlockAlveary.BOTTOM;
return BlockAlveary.SIEVE;
}
private void destroySieve() {
inventory.setInventorySlotContents(SLOT_SIEVE, null);
}
private void destroyPollen() {
for(int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) {
inventory.setInventorySlotContents(i, null);
}
}
private boolean canStorePollen() {
if(inventory.getStackInSlot(SLOT_SIEVE) == null)
return false;
for(int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) {
if(inventory.getStackInSlot(i) == null)
return true;
}
return false;
}
private void storePollenStack(ItemStack itemstack) {
for(int i = SLOT_POLLEN_1; i < SLOT_POLLEN_1 + SLOTS_POLLEN_COUNT; i++) {
if(inventory.getStackInSlot(i) == null) {
inventory.setInventorySlotContents(i, itemstack);
return;
}
}
}
/* INVENTORY */
public InventoryAdapter getInternalInventory() {
return inventory;
}
/* ICRAFTER */
@Override
public boolean canTakeStack(int slotIndex) {
return true;
}
@Override
public ItemStack takenFromSlot(int slotIndex, boolean consumeRecipe, EntityPlayer player) {
if(slotIndex == SLOT_SIEVE) {
destroyPollen();
return inventory.getStackInSlot(SLOT_SIEVE);
} else {
destroySieve();
return inventory.getStackInSlot(slotIndex);
}
}
@Override
public ItemStack getResult() {
return null;
}
/* IBEELISTENER */
@Override public void onQueenChange(ItemStack queen) {}
@Override public void wearOutEquipment(int amount) {}
@Override public void onQueenDeath(IBee queen) {}
@Override public void onPostQueenDeath(IBee queen) {}
@Override
public boolean onPollenRetrieved(IBee queen, IIndividual pollen, boolean isHandled) {
if(isHandled)
return isHandled;
if(!canStorePollen())
return false;
storePollenStack(AlleleManager.alleleRegistry.getSpeciesRoot(pollen.getClass()).getMemberStack(pollen, EnumGermlingType.POLLEN.ordinal()));
return true;
}
@Override
public boolean onEggLaid(IBee queen) {
return false;
}
}
@@ -0,0 +1,118 @@
/*******************************************************************************
* 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.gadgets;
import forestry.api.apiculture.IAlvearyComponent;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeModifier;
public class TileAlvearyStabiliser extends TileAlveary implements IBeeModifier {
public static final int BLOCK_META = 6;
public TileAlvearyStabiliser() {
super(BLOCK_META);
}
/* UPDATING */
@Override
public void initialize() {
super.initialize();
if(!hasMaster() || !isIntegratedIntoStructure())
return;
((IAlvearyComponent)getCentralTE()).registerBeeModifier(this);
}
@Override
protected void updateServerSide() {
super.updateServerSide();
if(worldObj.getTotalWorldTime() % 200 != 0)
return;
if(!hasMaster() || !isIntegratedIntoStructure())
return;
((IAlvearyComponent)getCentralTE()).registerBeeModifier(this);
}
@Override
public String getInventoryName() {
return "tile.alveary.6";
}
@Override
public boolean hasFunction() {
return true;
}
/* TEXTURES */
public int getIcon(int side, int metadata) {
if(side == 0 || side == 1)
return BlockAlveary.BOTTOM;
return BlockAlveary.STABILISER;
}
/* IBEEMODIFIER */
@Override
public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
return 0.0f;
}
@Override
public float getTerritoryModifier(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
return 1.0f;
}
@Override
public float getProductionModifier(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public float getFloweringModifier(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public float getGeneticDecay(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public boolean isSealed() {
return false;
}
@Override
public boolean isSelfLighted() {
return false;
}
@Override
public boolean isSunlightSimulated() {
return false;
}
@Override
public boolean isHellish() {
return false;
}
}
@@ -0,0 +1,307 @@
/*******************************************************************************
* 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.gadgets;
import java.util.Map.Entry;
import java.util.Stack;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.ForgeDirection;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IAlvearyComponent;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.core.ForestryAPI;
import forestry.api.core.ISpecialInventory;
import forestry.apiculture.worldgen.WorldGenHive;
import forestry.apiculture.worldgen.WorldGenHiveSwamer;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.utils.TileInventoryAdapter;
import forestry.plugins.PluginApiculture;
public class TileAlvearySwarmer extends TileAlveary implements ISpecialInventory {
/* CONSTANTS */
public static final int BLOCK_META = 2;
TileInventoryAdapter swarmerInventory;
private final Stack<ItemStack> pendingSpawns = new Stack<ItemStack>();
public TileAlvearySwarmer() {
super(BLOCK_META);
}
@Override
public void initialize() {
super.initialize();
if (swarmerInventory == null)
createInventory();
}
@Override
public void openGui(EntityPlayer player) {
player.openGui(ForestryAPI.instance, GuiId.AlvearySwarmerGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
}
/* UPDATING */
@Override
protected void updateServerSide() {
super.updateServerSide();
if (worldObj.getTotalWorldTime() % 100 != 0)
if (pendingSpawns.size() > 0)
trySpawnSwarm();
if (worldObj.getTotalWorldTime() % 500 != 0)
return;
if (!this.hasMaster())
return;
IAlvearyComponent master = (IAlvearyComponent) this.getCentralTE();
if (!(master instanceof IBeeHousing))
return;
IBeeHousing housing = (IBeeHousing) master;
ItemStack queenstack = housing.getQueen();
if (queenstack == null)
return;
if (!PluginApiculture.beeInterface.isMated(queenstack))
return;
// Calculate chance
int slot = getInducerSlot();
if (slot < 0)
return;
int chance = getChanceFor(swarmerInventory.getStackInSlot(slot));
// Remove resource
swarmerInventory.decrStackSize(slot, 1);
// Try to spawn princess
if (worldObj.rand.nextInt(1000) >= chance)
return;
// Queue swarm spawn
IBee spawn = PluginApiculture.beeInterface.getMember(queenstack);
spawn.setIsNatural(false);
pendingSpawns.push(PluginApiculture.beeInterface.getMemberStack(spawn, EnumBeeType.PRINCESS.ordinal()));
}
private int getChanceFor(ItemStack stack) {
for (Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) {
if (entry.getKey().isItemEqual(stack))
return entry.getValue();
}
return 0;
}
private int getInducerSlot() {
for (int i = 0; i < swarmerInventory.getSizeInventory(); i++) {
if (swarmerInventory.getStackInSlot(i) == null)
continue;
for (Entry<ItemStack, Integer> entry : BeeManager.inducers.entrySet()) {
if (entry.getKey().isItemEqual(swarmerInventory.getStackInSlot(i)))
return i;
}
}
return -1;
}
private void trySpawnSwarm() {
ItemStack toSpawn = pendingSpawns.peek();
WorldGenHive generator = new WorldGenHiveSwamer(new ItemStack[] { toSpawn });
int i = 0;
while (i < 10) {
i++;
int spawnX = xCoord + worldObj.rand.nextInt(40 * 2) - 40;
int spawnY = yCoord + worldObj.rand.nextInt(40);
int spawnZ = zCoord + worldObj.rand.nextInt(40 * 2) - 40;
if (generator.generate(worldObj, worldObj.rand, spawnX, spawnY, spawnZ)) {
pendingSpawns.pop();
break;
}
}
}
@Override
public boolean hasFunction() {
return true;
}
/* TEXTURES */
@Override
public int getIcon(int side, int metadata) {
if(side == 0 || side == 1)
return BlockAlveary.BOTTOM;
if (pendingSpawns.size() > 0)
return BlockAlveary.TX_56_SWON;
else
return BlockAlveary.TX_55_SWOF;
}
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
if (swarmerInventory == null)
createInventory();
swarmerInventory.readFromNBT(nbttagcompound);
NBTTagList nbttaglist = nbttagcompound.getTagList("PendingSpawns", 10);
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
pendingSpawns.add(ItemStack.loadItemStackFromNBT(nbttagcompound1));
}
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
if (swarmerInventory != null)
swarmerInventory.writeToNBT(nbttagcompound);
NBTTagList nbttaglist = new NBTTagList();
ItemStack[] offspring = pendingSpawns.toArray(new ItemStack[pendingSpawns.size()]);
for (int i = 0; i < offspring.length; i++)
if (offspring[i] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
offspring[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
nbttagcompound.setTag("PendingSpawns", nbttaglist);
}
@Override
protected void createInventory() {
swarmerInventory = new TileInventoryAdapter(this, 4, "SwarmInv");
}
@Override
public IInventory getInventory() {
return swarmerInventory;
}
/* ISPECIALINVENTORY */
@Override
public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
if (swarmerInventory != null)
return swarmerInventory.addStack(stack, false, doAdd);
else
return 0;
}
@Override
public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
return null;
}
/* IINVENTORY */
@Override
public int getSizeInventory() {
if (swarmerInventory != null)
return swarmerInventory.getSizeInventory();
else
return 0;
}
@Override
public ItemStack getStackInSlot(int slotIndex) {
if (swarmerInventory != null)
return swarmerInventory.getStackInSlot(slotIndex);
else
return null;
}
@Override
public ItemStack decrStackSize(int slotIndex, int amount) {
if (swarmerInventory != null)
return swarmerInventory.decrStackSize(slotIndex, amount);
else
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slotIndex) {
if (swarmerInventory != null)
return swarmerInventory.getStackInSlotOnClosing(slotIndex);
else
return null;
}
@Override
public void setInventorySlotContents(int slotIndex, ItemStack itemstack) {
// Client side handling for container synch
if (swarmerInventory == null && !Proxies.common.isSimulating(worldObj))
createInventory();
if (swarmerInventory != null)
swarmerInventory.setInventorySlotContents(slotIndex, itemstack);
}
@Override
public String getInventoryName() {
return "tile.alveary.2";
}
@Override
public int getInventoryStackLimit() {
if (swarmerInventory != null)
return swarmerInventory.getInventoryStackLimit();
else
return 0;
}
@Override public void openInventory() {}
@Override public void closeInventory() {}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return super.isUseableByPlayer(player);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean hasCustomInventoryName() {
return super.hasCustomInventoryName();
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
return super.isItemValidForSlot(slotIndex, itemstack);
}
}
@@ -0,0 +1,24 @@
/*******************************************************************************
* 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.gadgets;
import forestry.api.genetics.AlleleManager;
import forestry.apiculture.genetics.BeeHelper;
import forestry.core.gadgets.TileNaturalistChest;
import forestry.core.network.GuiId;
public class TileApiaristChest extends TileNaturalistChest {
public TileApiaristChest() {
super(AlleleManager.alleleRegistry.getSpeciesRoot(BeeHelper.UID), GuiId.ApiaristChestGUI.ordinal());
}
}
+355
View File
@@ -0,0 +1,355 @@
/*******************************************************************************
* 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.gadgets;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import buildcraft.api.gates.ITrigger;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IHiveFrame;
import forestry.api.core.ForestryAPI;
import forestry.core.gadgets.TileBase;
import forestry.core.network.GuiId;
import forestry.core.triggers.ForestryTrigger;
import forestry.plugins.PluginApiculture;
public class TileApiary extends TileBeehouse implements ISidedInventory {
@Override
public String getInventoryName() {
return "apiculture.0";
}
@Override
public void openGui(EntityPlayer player, TileBase tile) {
player.openGui(ForestryAPI.instance, GuiId.ApiaryGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
}
/* IBEEHOUSING */
@Override
public float getTerritoryModifier(IBeeGenome genome, float currentModifier) {
float mod = 1.0f;
for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) {
if (inventory.getStackInSlot(i) == null)
continue;
if (inventory.getStackInSlot(i).getItem() instanceof IHiveFrame)
mod *= ((IHiveFrame) inventory.getStackInSlot(i).getItem()).getTerritoryModifier(genome, mod);
}
return mod;
}
@Override
public float getProductionModifier(IBeeGenome genome, float currentModifier) {
float mod = 0.1f;
for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) {
if (inventory.getStackInSlot(i) == null)
continue;
if (inventory.getStackInSlot(i).getItem() instanceof IHiveFrame)
mod *= ((IHiveFrame) inventory.getStackInSlot(i).getItem()).getProductionModifier(genome, mod);
}
return mod;
}
@Override
public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
float mod = 1.0f;
for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) {
if (inventory.getStackInSlot(i) == null)
continue;
if (inventory.getStackInSlot(i).getItem() instanceof IHiveFrame)
mod *= ((IHiveFrame) inventory.getStackInSlot(i).getItem()).getMutationModifier(genome, mate, mod);
}
return mod;
}
@Override
public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
float mod = 1.0f;
for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) {
if (inventory.getStackInSlot(i) == null)
continue;
if (inventory.getStackInSlot(i).getItem() instanceof IHiveFrame)
mod *= ((IHiveFrame) inventory.getStackInSlot(i).getItem()).getLifespanModifier(genome, mate, mod);
}
return mod;
}
@Override
public float getFloweringModifier(IBeeGenome genome, float currentModifier) {
float mod = 1f;
for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) {
if (inventory.getStackInSlot(i) == null)
continue;
if (inventory.getStackInSlot(i).getItem() instanceof IHiveFrame)
mod *= ((IHiveFrame) inventory.getStackInSlot(i).getItem()).getFloweringModifier(genome, mod);
}
return mod;
}
@Override
public float getGeneticDecay(IBeeGenome genome, float currentModifier) {
float mod = 1f;
for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) {
if (inventory.getStackInSlot(i) == null)
continue;
if (inventory.getStackInSlot(i).getItem() instanceof IHiveFrame)
mod *= ((IHiveFrame) inventory.getStackInSlot(i).getItem()).getGeneticDecay(genome, mod);
}
return mod;
}
@Override
public void wearOutEquipment(int amount) {
int wear = Math.round(amount * PluginApiculture.beeInterface.getBeekeepingMode(worldObj).getWearModifier());
for (int i = SLOT_FRAMES_1; i < SLOT_FRAMES_1 + SLOT_FRAMES_COUNT; i++) {
if (inventory.getStackInSlot(i) == null)
continue;
if (!(inventory.getStackInSlot(i).getItem() instanceof IHiveFrame))
continue;
inventory.setInventorySlotContents(
i,
((IHiveFrame) inventory.getStackInSlot(i).getItem()).frameUsed(this, inventory.getStackInSlot(i),
PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN)), wear));
}
}
/* IINVENTORY */
@Override
protected boolean canTakeStackFromSide(int slotIndex, ItemStack itemstack, int side) {
if (!super.canTakeStackFromSide(slotIndex, itemstack, side))
return false;
switch (slotIndex) {
case SLOT_QUEEN:
case SLOT_DRONE:
case SLOT_FRAMES_1:
case SLOT_FRAMES_2:
case SLOT_FRAMES_3:
return false;
default:
return true;
}
}
@Override
protected boolean canPutStackFromSide(int slotIndex, ItemStack itemstack, int side) {
if (!super.canPutStackFromSide(slotIndex, itemstack, side))
return false;
if (slotIndex == SLOT_QUEEN && PluginApiculture.beeInterface.isMember(itemstack)
&& !PluginApiculture.beeInterface.isDrone(itemstack))
return true;
if (slotIndex == SLOT_DRONE && PluginApiculture.beeInterface.isDrone(itemstack))
return true;
return false;
}
/**
* TODO: just a specialsource workaround
*/
@Override
public ItemStack getStackInSlot(int i) {
return super.getStackInSlot(i);
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
super.setSlotContents(i, itemstack);
}
@Override
public int getSizeInventory() {
return inventory.getSizeInventory();
}
@Override
public ItemStack decrStackSize(int i, int j) {
return inventory.decrStackSize(i, j);
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
return inventory.getStackInSlotOnClosing(slot);
}
@Override
public int getInventoryStackLimit() {
return inventory.getInventoryStackLimit();
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return super.isUseableByPlayer(player);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean hasCustomInventoryName() {
return super.hasCustomInventoryName();
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) {
return super.isItemValidForSlot(slotIndex, itemstack);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean canInsertItem(int i, ItemStack itemstack, int j) {
return super.canInsertItem(i, itemstack, j);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public boolean canExtractItem(int i, ItemStack itemstack, int j) {
return super.canExtractItem(i, itemstack, j);
}
/**
* TODO: just a specialsource workaround
*/
@Override
public int[] getAccessibleSlotsFromSide(int side) {
return super.getAccessibleSlotsFromSide(side);
}
/* ISPECIALINVENTORY */
// @Override
// public ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount) {
// ItemStack product = null;
//
// for (int i = SLOT_PRODUCT_1; i < SLOT_PRODUCT_1 + SLOT_PRODUCT_COUNT; i++) {
// if (inventory.getStackInSlot(i) == null)
// continue;
//
// // Princesses can only be extracted from top.
// if (ForestryItem.beePrincessGE.isItemEqual(inventory.getStackInSlot(i))) {
// if (PluginApiculture.apiarySideSensitive && from != ForgeDirection.UP)
// continue;
//
// product = inventory.getStackInSlot(i).copy();
// if (doRemove) {
// inventory.getStackInSlot(i).stackSize = 0;
// inventory.setInventorySlotContents(i, null);
// }
// break;
//
// // Drones can only be extracted from the bottom.
// } else if (ForestryItem.beeDroneGE.isItemEqual(inventory.getStackInSlot(i))) {
// if (PluginApiculture.apiarySideSensitive && from != ForgeDirection.DOWN)
// continue;
//
// product = StackUtils.createSplitStack(inventory.getStackInSlot(i), 1);
// product.stackSize = 1;
// if (doRemove) {
// inventory.getStackInSlot(i).stackSize--;
// if (inventory.getStackInSlot(i).stackSize <= 0)
// inventory.setInventorySlotContents(i, null);
// }
// break;
//
// // Everything else to be extracted from the sides
// } else {
// if (PluginApiculture.apiarySideSensitive && (from == ForgeDirection.UP || from == ForgeDirection.DOWN))
// continue;
//
// product = StackUtils.createSplitStack(inventory.getStackInSlot(i), 1);
// if (doRemove) {
// inventory.getStackInSlot(i).stackSize--;
// if (inventory.getStackInSlot(i).stackSize <= 0)
// inventory.setInventorySlotContents(i, null);
// }
// break;
// }
// }
//
// return new ItemStack[] { product };
// }
//
// @Override
// public int addItem(ItemStack stack, boolean doAdd, ForgeDirection from) {
// // Princesses && Queens
// if (ForestryItem.beePrincessGE.isItemEqual(stack) || ForestryItem.beeQueenGE.isItemEqual(stack))
// if (inventory.getStackInSlot(SLOT_QUEEN) == null) {
// if (doAdd) {
// inventory.setInventorySlotContents(SLOT_QUEEN, stack.copy());
// inventory.getStackInSlot(SLOT_QUEEN).stackSize = 1;
// }
//
// return 1;
// }
//
// // Drones
// if (ForestryItem.beeDroneGE.isItemEqual(stack)) {
//
// ItemStack droneStack = inventory.getStackInSlot(SLOT_DRONE);
// if (droneStack == null) {
// if (doAdd)
// inventory.setInventorySlotContents(SLOT_DRONE, stack.copy());
// return stack.stackSize;
// } else {
// if (!droneStack.isItemEqual(stack))
// return 0;
// if (!ItemStack.areItemStackTagsEqual(droneStack, stack))
// return 0;
// int space = droneStack.getMaxStackSize() - droneStack.stackSize;
// if (space <= 0)
// return 0;
//
// int added = space > stack.stackSize ? stack.stackSize : space;
// if (doAdd)
// droneStack.stackSize += added;
// return added;
// }
// }
//
// return 0;
// }
/* ITRIGGERPROVIDER */
@Override
public LinkedList<ITrigger> getCustomTriggers() {
LinkedList<ITrigger> res = new LinkedList<ITrigger>();
res.add(ForestryTrigger.missingQueen);
res.add(ForestryTrigger.missingDrone);
res.add(PluginApiculture.triggerNoFrames);
return res;
}
}
+448
View File
@@ -0,0 +1,448 @@
/*******************************************************************************
* 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.gadgets;
import com.mojang.authlib.GameProfile;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeekeepingLogic;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.core.ForestryAPI;
import forestry.api.genetics.IIndividual;
import forestry.core.EnumErrorCode;
import forestry.core.config.Config;
import forestry.core.config.ForestryItem;
import forestry.core.gadgets.TileBase;
import forestry.core.interfaces.IClimatised;
import forestry.core.network.GuiId;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketInventoryStack;
import forestry.core.network.PacketTileUpdate;
import forestry.core.proxy.Proxies;
import forestry.core.utils.InventoryAdapter;
import forestry.core.utils.Utils;
import forestry.plugins.PluginApiculture;
public class TileBeehouse extends TileBase implements IBeeHousing, IClimatised {
// CONSTANTS
public static final int SLOT_QUEEN = 0;
public static final int SLOT_DRONE = 1;
public static final int SLOT_INVENTORY_1 = 2;
protected static int SLOT_PRODUCT_1 = 2;
protected static int SLOT_PRODUCT_COUNT = 7;
public static final int SLOT_FRAMES_1 = 9;
public static final int SLOT_FRAMES_2 = 10;
public static final int SLOT_FRAMES_3 = 11;
public static final int SLOT_INVENTORY_COUNT = 7;
public static final int SLOT_FRAMES_COUNT = 3;
// Inventory
protected InventoryAdapter inventory = new InventoryAdapter(12, "Items");
private final IBeekeepingLogic logic;
private int biomeId = -1;
private float temperature;
private float humidity;
private int displayHealthMax = 0;
private int displayHealth = 0;
public TileBeehouse() {
setHints(Config.hints.get("apiary"));
logic = PluginApiculture.beeInterface.createBeekeepingLogic(this);
}
@Override
public String getInventoryName() {
return "apiculture.2";
}
@Override
public void openGui(EntityPlayer player, TileBase tile) {
player.openGui(ForestryAPI.instance, GuiId.BeehouseGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
}
/* LOADING & SAVING */
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setFloat("Temp", temperature);
nbttagcompound.setFloat("Humidity", humidity);
nbttagcompound.setInteger("BiomeId", biomeId);
inventory.writeToNBT(nbttagcompound);
if (logic != null)
logic.writeToNBT(nbttagcompound);
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
temperature = nbttagcompound.getFloat("Temp");
humidity = nbttagcompound.getFloat("Humidity");
biomeId = nbttagcompound.getInteger("BiomeId");
inventory.readFromNBT(nbttagcompound);
logic.readFromNBT(nbttagcompound);
}
@Override
public void initialize() {
super.initialize();
updateBiome();
}
@Override
public void validate() {
updateBiome();
}
/* ICLIMATISED */
@Override
public boolean isClimatized() {
return true;
}
@Override
public EnumTemperature getTemperature() {
if (EnumTemperature.isBiomeHellish(biomeId))
return EnumTemperature.HELLISH;
return EnumTemperature.getFromValue(temperature);
}
@Override
public EnumHumidity getHumidity() {
return EnumHumidity.getFromValue(humidity);
}
@Override
public float getExactTemperature() {
return this.temperature;
}
@Override
public float getExactHumidity() {
return this.humidity;
}
/* UPDATING */
@Override
public void updateClientSide() {
// / Multiplayer FX
if (PluginApiculture.beeInterface.isMated(inventory.getStackInSlot(SLOT_QUEEN)))
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 % 2 == 0) {
IBee displayQueen = PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN));
displayQueen.doFX(logic.getEffectData(), this);
}
return;
}
@Override
public void updateServerSide() {
logic.update();
IBee queen = logic.getQueen();
if (queen == null)
return;
// Add swarm effects
if (worldObj.getTotalWorldTime() % 200 * 10 == 0)
onQueenChange(inventory.getStackInSlot(SLOT_QUEEN));
/* These should get already done on the client / doesn't work server-side anyway
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 2 % 2 == 0)
queen.doFX(logic.getEffectData(), this);
if (getErrorState() == EnumErrorCode.OK && worldObj.getTotalWorldTime() % 50 == 0) {
float f = xCoord + 0.5F;
float f1 = yCoord + 0.0F + (worldObj.rand.nextFloat() * 6F) / 16F;
float f2 = zCoord + 0.5F;
float f3 = 0.52F;
float f4 = worldObj.rand.nextFloat() * 0.6F - 0.3F;
Proxies.common.addEntitySwarmFX(worldObj, (f - f3), f1, (f2 + f4), 0F, 0F, 0F);
Proxies.common.addEntitySwarmFX(worldObj, (f + f3), f1, (f2 + f4), 0F, 0F, 0F);
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 - f3), 0F, 0F, 0F);
Proxies.common.addEntitySwarmFX(worldObj, (f + f4), f1, (f2 + f3), 0F, 0F, 0F);
}*/
}
// @Override
public boolean isWorking() {
return getErrorState() == EnumErrorCode.OK;
}
@Override
public boolean addProduct(ItemStack product, boolean all) {
return inventory.tryAddStack(product, SLOT_PRODUCT_1, SLOT_PRODUCT_COUNT, all, true);
}
/* NETWORK SYNCH */
@Override
public void onQueenChange(ItemStack queenStack) {
if (!Proxies.common.isSimulating(worldObj))
return;
Proxies.net.sendNetworkPacket(new PacketInventoryStack(PacketIds.IINVENTORY_STACK, xCoord, yCoord, zCoord, SLOT_QUEEN, queenStack), xCoord, yCoord,
zCoord);
Proxies.net.sendNetworkPacket(new PacketTileUpdate(this), xCoord, yCoord, zCoord);
}
/* STATE INFORMATION */
private int getHealthDisplay() {
if (inventory.getStackInSlot(SLOT_QUEEN) == null)
return 0;
if (ForestryItem.beeQueenGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN)))
return PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getHealth();
else if (ForestryItem.beePrincessGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN)))
return displayHealth;
else
return 0;
}
private int getMaxHealthDisplay() {
if (inventory.getStackInSlot(SLOT_QUEEN) == null)
return 0;
if (ForestryItem.beeQueenGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN)))
return PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(SLOT_QUEEN)).getMaxHealth();
else if (ForestryItem.beePrincessGE.isItemEqual(inventory.getStackInSlot(SLOT_QUEEN)))
return displayHealthMax;
else
return 0;
}
/**
* Returns scaled queen health or breeding progress
*
* @param i
* @return
*/
public int getHealthScaled(int i) {
if (getMaxHealthDisplay() == 0)
return 0;
return (getHealthDisplay() * i) / getMaxHealthDisplay();
}
public int getTemperatureScaled(int i) {
return Math.round(i * (temperature / 2));
}
public int getHumidityScaled(int i) {
return Math.round(i * humidity);
}
public void updateBiome() {
if (worldObj != null) {
BiomeGenBase biome = Utils.getBiomeAt(worldObj, xCoord, zCoord);
if (biome != null) {
this.biomeId = biome.biomeID;
this.temperature = biome.temperature;
this.humidity = biome.rainfall;
setErrorState(EnumErrorCode.OK);
}
}
}
/* SMP */
// @Override
public void getGUINetworkData(int i, int j) {
if (logic == null)
return;
switch (i) {
case 0:
displayHealth = j;
break;
case 1:
displayHealthMax = j;
break;
}
}
// @Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
if (logic == null)
return;
iCrafting.sendProgressBarUpdate(container, 0, logic.getBreedingTime());
iCrafting.sendProgressBarUpdate(container, 1, logic.getTotalBreedingTime());
}
/* INVENTORY MANAGMENT */
@Override
public InventoryAdapter getInternalInventory() {
return inventory;
}
public ItemStack getStackInSlot(int i) {
return inventory.getStackInSlot(i);
}
public void setSlotContents(int i, ItemStack itemstack) {
inventory.setInventorySlotContents(i, itemstack);
}
// / IBEEHOUSING
@Override
public int getXCoord() {
return xCoord;
}
@Override
public int getYCoord() {
return yCoord;
}
@Override
public int getZCoord() {
return zCoord;
}
@Override
public int getBiomeId() {
return this.biomeId;
}
@Override
public ItemStack getQueen() {
return getStackInSlot(SLOT_QUEEN);
}
@Override
public ItemStack getDrone() {
return getStackInSlot(SLOT_DRONE);
}
@Override
public void setQueen(ItemStack itemstack) {
setSlotContents(SLOT_QUEEN, itemstack);
}
@Override
public void setDrone(ItemStack itemstack) {
setSlotContents(SLOT_DRONE, itemstack);
}
@Override
public World getWorld() {
return worldObj;
}
@Override
public void setErrorState(int state) {
setErrorState(EnumErrorCode.values()[state]);
}
@Override
public int getErrorOrdinal() {
return getErrorState().ordinal();
}
@Override
public boolean canBreed() {
return true;
}
@Override
public float getTerritoryModifier(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public float getProductionModifier(IBeeGenome genome, float currentModifier) {
return 0.25f;
}
@Override
public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
return 0.0f;
}
@Override
public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
return 3.0f;
}
@Override
public float getFloweringModifier(IBeeGenome genome, float currentModifier) {
return 3.0f;
}
@Override
public float getGeneticDecay(IBeeGenome genome, float currentModifier) {
return 0.0f;
}
@Override
public void wearOutEquipment(int amount) {
}
@Override
public boolean isSealed() {
return false;
}
@Override
public boolean isSelfLighted() {
return false;
}
@Override
public boolean isSunlightSimulated() {
return false;
}
@Override
public boolean isHellish() {
return false;
}
@Override
public void onQueenDeath(IBee queen) {
}
@Override
public void onPostQueenDeath(IBee queen) {
}
@Override
public boolean onPollenRetrieved(IBee queen, IIndividual pollen, boolean isHandled) {
return false;
}
@Override
public boolean onEggLaid(IBee queen) {
return false;
}
/* IHousing */
@Override
public GameProfile getOwnerName() {
return this.getOwnerProfile();
}
}
+85
View File
@@ -0,0 +1,85 @@
/*******************************************************************************
* 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.gadgets;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
public class TileCandle extends TileEntity {
private int colour;
// This is a non-ticking Tile Entity.
@Override
public boolean canUpdate() {
return false;
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound nbt = new NBTTagCompound();
writeToNBT(nbt);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, nbt);
}
@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
readFromNBT(pkt.func_148857_g());
}
@Override
public void readFromNBT(NBTTagCompound tagRoot) {
super.readFromNBT(tagRoot);
this.setColour(tagRoot.getInteger("colour"));
}
@Override
public void writeToNBT(NBTTagCompound tagRoot) {
super.writeToNBT(tagRoot);
tagRoot.setInteger("colour", this.colour);
}
public int getColour() {
return this.colour;
}
public void setColour(int value) {
this.colour = value;
}
public void setColour(int red, int green, int blue) {
this.colour = toIntColour(red, green, blue);
}
/*public void setColour(int[] cs) {
this.colour = toIntColour(cs[0], cs[1], cs[2]);
}*/
public void addColour(int red, int green, int blue) {
int[] myColour = fromIntColour(this.colour);
this.colour = toIntColour((red + myColour[0]) / 2, (green + myColour[0]) / 2, (blue + myColour[2]) / 2);
}
private static int[] fromIntColour(int value) {
int[] cs = new int[3];
cs[0] = (value & 0xff0000) >> 16;
cs[1] = (value & 0x00ff00) >> 8;
cs[2] = value & 0x0000ff;
return cs;
}
private static int toIntColour(int r, int g, int b) {
return r << 16 | g << 8 | b;
}
}
+55
View File
@@ -0,0 +1,55 @@
/*******************************************************************************
* 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.gadgets;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import forestry.core.utils.InventoryAdapter;
public class TileSwarm extends TileEntity {
public InventoryAdapter contained = new InventoryAdapter(2, "Contained");
@Override
public boolean canUpdate() {
return false;
}
public TileSwarm setContained(ItemStack[] bees) {
for (ItemStack itemstack : bees)
contained.addStack(itemstack, false, true);
return this;
}
public boolean containsBees() {
for (int i = 0; i < contained.getSizeInventory(); i++)
if (contained.getStackInSlot(i) != null)
return true;
return false;
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
contained.readFromNBT(nbttagcompound);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
contained.writeToNBT(nbttagcompound);
}
}
@@ -0,0 +1,90 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.RandomPositionGenerator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.pathfinding.PathEntity;
import net.minecraft.pathfinding.PathNavigate;
import net.minecraft.util.Vec3;
public class AIAvoidPlayers extends EntityAIBase {
private final EntityCreature mob;
private final float farSpeed;
private final float nearSpeed;
private final float minDistance;
private PathEntity pathing;
private final PathNavigate pathNavigator;
private EntityPlayer player;
public AIAvoidPlayers(EntityCreature mob, float minDistance, float farSpeed, float nearSpeed) {
this.mob = mob;
this.minDistance = minDistance;
this.farSpeed = farSpeed;
this.nearSpeed = nearSpeed;
this.pathNavigator = mob.getNavigator();
this.setMutexBits(1);
}
@Override
public boolean shouldExecute() {
player = mob.worldObj.getClosestPlayerToEntity(mob, minDistance);
if (player == null)
return false;
if (!mob.getEntitySenses().canSee(player))
return false;
Vec3 randomTarget = RandomPositionGenerator.findRandomTargetBlockAwayFrom(mob, 16, 7,
Vec3.createVectorHelper(player.posX, player.posY, player.posZ));
if (randomTarget == null)
return false;
if (player.getDistanceSq(randomTarget.xCoord, randomTarget.yCoord, randomTarget.zCoord) < player.getDistanceSqToEntity(mob))
return false;
pathing = pathNavigator.getPathToXYZ(randomTarget.xCoord, randomTarget.yCoord, randomTarget.zCoord);
return pathing == null ? false : pathing.isDestinationSame(randomTarget);
}
@Override
public boolean continueExecuting() {
return !this.pathNavigator.noPath();
}
@Override
public void startExecuting() {
this.pathNavigator.setPath(pathing, farSpeed);
}
@Override
public void resetTask() {
player = null;
}
@Override
public void updateTask() {
if (mob.getDistanceSqToEntity(player) < 49.0D)
mob.getNavigator().setSpeed(nearSpeed);
else
mob.getNavigator().setSpeed(farSpeed);
}
}
@@ -0,0 +1,238 @@
/*******************************************************************************
* 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.genetics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import com.mojang.authlib.GameProfile;
import forestry.api.apiculture.EnumBeeChromosome;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeRoot;
import forestry.api.core.IIconProvider;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IClassification;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IMutation;
import forestry.core.config.Defaults;
import forestry.core.genetics.AlleleSpecies;
import forestry.core.render.TextureManager;
import forestry.core.utils.StackUtils;
public class AlleleBeeSpecies extends AlleleSpecies implements IAlleleBeeSpecies, IIconProvider {
public IJubilanceProvider jubilanceProvider;
private final IBeeRoot root;
private final HashMap<ItemStack, Integer> products = new HashMap<ItemStack, Integer>();
private final HashMap<ItemStack, Integer> specialty = new HashMap<ItemStack, Integer>();
private String texture;
private final int primaryColour;
private final int secondaryColour;
private final String iconType = "default";
public AlleleBeeSpecies(String uid, boolean dominant, String name, IClassification branch, int primaryColor, int secondaryColor) {
this(uid, dominant, name, branch, null, primaryColor, secondaryColor);
}
public AlleleBeeSpecies(String uid, boolean dominant, String name, IClassification branch, String binomial, int primaryColor, int secondaryColor) {
this(uid, dominant, name, branch, binomial, primaryColor, secondaryColor, new JubilanceDefault());
}
public AlleleBeeSpecies(String uid, boolean dominant, String name, IClassification branch, String binomial, int primaryColor, int secondaryColor,
IJubilanceProvider jubilanceProvider) {
super(uid, dominant, name, branch, binomial);
this.root = (IBeeRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootBees");
this.primaryColour = primaryColor;
this.secondaryColour = secondaryColor;
this.jubilanceProvider = jubilanceProvider;
texture = Defaults.TEXTURE_PATH_ENTITIES + "/bees/honeyBee.png";
}
@Override
public IBeeRoot getRoot() {
return root;
}
public AlleleBeeSpecies setEntityTexture(String texture) {
this.texture = Defaults.TEXTURE_PATH_ENTITIES + "/bees/" + texture + ".png";
return this;
}
public AlleleBeeSpecies addProduct(ItemStack product, int chance) {
this.products.put(product, chance);
return this;
}
public AlleleBeeSpecies addSpecialty(ItemStack specialty, int chance) {
this.specialty.put(specialty, chance);
return this;
}
public AlleleBeeSpecies setJubilanceProvider(IJubilanceProvider provider) {
this.jubilanceProvider = provider;
return this;
}
/* RESEARCH */
@Override
public int getComplexity() {
return 1 + getGeneticAdvancement(this, new ArrayList<IAllele>());
}
private int getGeneticAdvancement(IAllele species, ArrayList<IAllele> exclude) {
int own = 1;
int highest = 0;
exclude.add(species);
for(IMutation mutation : getRoot().getPaths(species, EnumBeeChromosome.SPECIES.ordinal())) {
if(!exclude.contains(mutation.getAllele0())) {
int otherAdvance = getGeneticAdvancement(mutation.getAllele0(), exclude);
if(otherAdvance > highest)
highest = otherAdvance;
}
if(!exclude.contains(mutation.getAllele1())) {
int otherAdvance = getGeneticAdvancement(mutation.getAllele1(), exclude);
if(otherAdvance > highest)
highest = otherAdvance;
}
}
return own + (highest < 0 ? 0 : highest);
}
@Override
public float getResearchSuitability(ItemStack itemstack) {
if(itemstack == null)
return 0f;
for(ItemStack stack : products.keySet())
if(stack.isItemEqual(itemstack))
return 1.0f;
for(ItemStack stack : specialty.keySet())
if(stack.isItemEqual(itemstack))
return 1.0f;
return super.getResearchSuitability(itemstack);
}
@Override
public ItemStack[] getResearchBounty(World world, GameProfile researcher, IIndividual individual, int bountyLevel) {
ArrayList<ItemStack> bounty = new ArrayList<ItemStack>();
for(ItemStack stack : super.getResearchBounty(world, researcher, individual, bountyLevel))
bounty.add(stack);
if(bountyLevel > 10) {
for(ItemStack stack : specialty.keySet()) {
bounty.add(StackUtils.copyWithRandomSize(stack, (int)((float)bountyLevel / 2), world.rand));
}
}
for(ItemStack stack : products.keySet()) {
bounty.add(StackUtils.copyWithRandomSize(stack, (int)((float)bountyLevel / 2), world.rand));
}
return bounty.toArray(StackUtils.EMPTY_STACK_ARRAY);
}
/* OTHER */
@Override
public boolean isNocturnal() {
return false;
}
@Override
public HashMap<ItemStack, Integer> getProducts() {
return products;
}
@Override
public HashMap<ItemStack, Integer> getSpecialty() {
return specialty;
}
@Override
public boolean isJubilant(IBeeGenome genome, IBeeHousing housing) {
return jubilanceProvider.isJubilant(this, genome, housing);
}
@Override
public String getEntityTexture() {
return texture;
}
@Override
public int getIconColour(int renderPass) {
if (renderPass == 0)
return primaryColour;
if (renderPass == 1)
return secondaryColour;
return 0xffffff;
}
@SideOnly(Side.CLIENT)
private static IIcon[][] icons;
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister register) {
icons = new IIcon[EnumBeeType.values().length][3];
IIcon body1 = TextureManager.getInstance().registerTex(register, "bees/" + iconType + "/body1");
for (int i = 0; i < EnumBeeType.values().length; i++) {
if(EnumBeeType.values()[i] == EnumBeeType.NONE)
continue;
icons[i][0] = TextureManager.getInstance().registerTex(register, "bees/" + iconType + "/" + EnumBeeType.values()[i].toString().toLowerCase(Locale.ENGLISH) + ".outline");;
icons[i][1] = (EnumBeeType.values()[i] != EnumBeeType.LARVAE) ? body1
: TextureManager.getInstance().registerTex(register, "bees/" + iconType + "/" + EnumBeeType.values()[i].toString().toLowerCase(Locale.ENGLISH) + ".body");
icons[i][2] = TextureManager.getInstance().registerTex(register, "bees/" + iconType + "/" + EnumBeeType.values()[i].toString().toLowerCase(Locale.ENGLISH) + ".body2");
}
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(EnumBeeType type, int renderPass) {
return icons[type.ordinal()][renderPass];
}
@Override
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider() {
return this;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(short texUID) {
return null;
}
}
@@ -0,0 +1,70 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.apiculture.items.ItemArmorApiarist;
import forestry.core.utils.DamageSourceForestry;
public class AlleleEffectAggressive extends AlleleEffectThrottled {
public static DamageSource damageSourceBeeAggressive = new DamageSourceForestry("bee.aggressive");
public AlleleEffectAggressive(String uid) {
super(uid, "aggressive", true, 40, false, false);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
if (isHalted(storedData, housing))
return storedData;
AxisAlignedBB hurtBox = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = housing.getWorld().getEntitiesWithinAABB(EntityLivingBase.class, hurtBox);
for (Object obj : list) {
EntityLivingBase entity = (EntityLivingBase) obj;
int damage = 4;
// Players are not attacked if they wear a full set of apiarist's
// armor.
if (entity instanceof EntityPlayer) {
int count = ItemArmorApiarist.wearsItems((EntityPlayer) entity, getUID(), true);
// Full set, no damage/effect
if (count > 3)
continue;
else if (count > 2)
damage = 1;
else if (count > 1)
damage = 2;
else if (count > 0)
damage = 3;
}
entity.attackEntityFrom(damageSourceBeeAggressive, damage);
}
return storedData;
}
}
@@ -0,0 +1,114 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.apiculture.items.ItemArmorApiarist;
import forestry.core.genetics.EffectData;
public class AlleleEffectCreeper extends AlleleEffectThrottled {
private final int explosionChance = 50;
byte defaultForce = 12;
byte indexExplosionTimer = 1;
byte indexExplosionForce = 2;
public AlleleEffectCreeper(String uid) {
super(uid, "creeper", true, 20, false, true);
}
@Override
public IEffectData validateStorage(IEffectData storedData) {
if (!(storedData instanceof EffectData))
return new EffectData(3, 0);
if (((EffectData) storedData).getIntSize() < 3)
return new EffectData(3, 0);
return storedData;
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
World world = housing.getWorld();
if (isHalted(storedData, housing))
return storedData;
// If we are already triggered, we continue the explosion sequence.
if (storedData.getInteger(indexExplosionTimer) > 0) {
progressExplosion(storedData, world, housing.getXCoord(), housing.getYCoord(), housing.getZCoord());
return storedData;
}
AxisAlignedBB infectionBox = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = world.getEntitiesWithinAABB(EntityPlayer.class, infectionBox);
for (Object obj : list) {
EntityPlayer player = (EntityPlayer) obj;
int chance = explosionChance;
storedData.setInteger(indexExplosionForce, defaultForce);
// Players are not attacked if they wear a full set of apiarist's
// armor.
int count = ItemArmorApiarist.wearsItems(player, getUID(), true);
// Full set, no damage/effect
if (count > 3)
continue;
else if (count > 2) {
chance = 5;
storedData.setInteger(indexExplosionForce, 6);
} else if (count > 1) {
chance = 20;
storedData.setInteger(indexExplosionForce, 8);
} else if (count > 0) {
chance = 35;
storedData.setInteger(indexExplosionForce, 10);
}
if (world.rand.nextInt(1000) >= chance)
continue;
world.playSoundEffect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord(), "mob.creeper", 4F,
(1.0F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.2F) * 0.7F);
storedData.setInteger(indexExplosionTimer, 2); // Set explosion
// timer
}
return storedData;
}
private void progressExplosion(IEffectData storedData, World world, int x, int y, int z) {
int explosionTimer = storedData.getInteger(indexExplosionTimer);
explosionTimer--;
storedData.setInteger(indexExplosionTimer, explosionTimer);
if (explosionTimer > 0)
return;
world.createExplosion(null, x, y, z, storedData.getInteger(indexExplosionForce), false);
}
}
@@ -0,0 +1,46 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
public class AlleleEffectExploration extends AlleleEffectThrottled {
public AlleleEffectExploration(String uid) {
super(uid, "exploration", false, 80, true, false);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
if (isHalted(storedData, housing))
return storedData;
AxisAlignedBB beatifyBox = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = housing.getWorld().getEntitiesWithinAABB(EntityPlayer.class, beatifyBox);
for (Object obj : list) {
EntityPlayer player = (EntityPlayer) obj;
player.addExperience(2);
}
return storedData;
}
}
@@ -0,0 +1,73 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.core.EnumTemperature;
import forestry.api.genetics.IEffectData;
import forestry.core.proxy.Proxies;
import forestry.core.utils.Vect;
public class AlleleEffectGlacial extends AlleleEffectThrottled {
public AlleleEffectGlacial(String uid) {
super(uid, "glacial", false, 200, true, false);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
World world = housing.getWorld();
if (isHalted(storedData, housing))
return storedData;
EnumTemperature temp = EnumTemperature.getFromValue(BiomeGenBase.getBiome(housing.getBiomeId()).temperature);
switch (temp) {
case HELLISH:
case HOT:
case WARM:
return storedData;
default:
}
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
for (int i = 0; i < 10; i++) {
Vect randomPos = new Vect(world.rand.nextInt(area.x), world.rand.nextInt(area.y), world.rand.nextInt(area.z));
Vect posBlock = randomPos.add(new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()));
posBlock = posBlock.add(offset);
// Freeze water
Block block = world.getBlock(posBlock.x, posBlock.y, posBlock.z);
if (block != Blocks.water)
continue;
if (!world.isAirBlock(posBlock.x, posBlock.y + 1, posBlock.z))
continue;
Proxies.common.setBlockWithNotify(world, posBlock.x, posBlock.y, posBlock.z, Blocks.ice);
}
return storedData;
}
}
@@ -0,0 +1,47 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
public class AlleleEffectHeroic extends AlleleEffectThrottled {
public AlleleEffectHeroic(String uid) {
super(uid, "heroic", false, 40, true, false);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
if (isHalted(storedData, housing))
return storedData;
AxisAlignedBB hurtBox = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = housing.getWorld().getEntitiesWithinAABB(EntityMob.class, hurtBox);
for (Object obj : list) {
EntityMob mob = (EntityMob) obj;
mob.attackEntityFrom(DamageSource.generic, 2);
}
return storedData;
}
}
@@ -0,0 +1,95 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.apiculture.items.ItemArmorApiarist;
import forestry.plugins.PluginApiculture;
public class AlleleEffectIgnition extends AlleleEffectThrottled {
int ignitionChance = 50;
int fireDuration = 500;
public AlleleEffectIgnition(String uid) {
super(uid, "ignition", false, 20, false, true);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
World world = housing.getWorld();
if (isHalted(storedData, housing))
return storedData;
AxisAlignedBB hurtBox = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = world.getEntitiesWithinAABB(EntityLivingBase.class, hurtBox);
for (Object obj : list) {
EntityLivingBase entity = (EntityLivingBase) obj;
int chance = ignitionChance;
int duration = fireDuration;
// Players are not attacked if they wear a full set of apiarist's
// armor.
if (entity instanceof EntityPlayer) {
int count = ItemArmorApiarist.wearsItems((EntityPlayer) entity, getUID(), true);
// Full set, no damage/effect
if (count > 3)
continue;
else if (count > 2) {
chance = 5;
duration = 50;
} else if (count > 1) {
chance = 20;
duration = 200;
} else if (count > 0) {
chance = 35;
duration = 350;
}
}
if (world.rand.nextInt(1000) >= chance)
continue;
entity.setFire(duration);
}
return storedData;
}
@Override
public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
int[] area = getModifiedArea(genome, housing);
if (housing.getWorld().rand.nextBoolean())
PluginApiculture.proxy.addBeeHiveFX("particles/swarm_bee", housing.getWorld(), housing.getXCoord(), housing.getYCoord(),
housing.getZCoord(), genome.getPrimary().getIconColour(0), area[0], area[1], area[2]);
else
PluginApiculture.proxy.addBeeHiveFX("particles/ember", housing.getWorld(), housing.getXCoord(), housing.getYCoord(),
housing.getZCoord(), 0xffffff, area[0], area[1], area[2]);
return storedData;
}
}
@@ -0,0 +1,89 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.apiculture.items.ItemArmorApiarist;
import forestry.plugins.PluginApiculture;
public class AlleleEffectMiasmic extends AlleleEffectThrottled {
private final int infectionChance = 50;
public AlleleEffectMiasmic(String uid) {
super(uid, "misasmic", false, 50, false, false);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
World world = housing.getWorld();
if (isHalted(storedData, housing))
return storedData;
AxisAlignedBB infectionBox = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = world.getEntitiesWithinAABB(EntityPlayer.class, infectionBox);
for (Object obj : list) {
if (world.rand.nextInt(1000) >= infectionChance)
continue;
EntityPlayer player = (EntityPlayer) obj;
int duration = 800;
// Players are not attacked if they wear a full set of apiarist's
// armor.
int count = ItemArmorApiarist.wearsItems(player, getUID(), true);
// Full set, no damage/effect
if (count > 3)
continue;
else if (count > 2)
duration = 200;
else if (count > 1)
duration = 400;
else if (count > 0)
duration = 600;
player.addPotionEffect(new PotionEffect(Potion.poison.id, duration, 0));
}
return storedData;
}
@Override
public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
int[] area = getModifiedArea(genome, housing);
if (housing.getWorld().rand.nextBoolean())
PluginApiculture.proxy.addBeeHiveFX("particles/swarm_bee", housing.getWorld(), housing.getXCoord(), housing.getYCoord(),
housing.getZCoord(), genome.getPrimary().getIconColour(0), area[0], area[1], area[2]);
else
PluginApiculture.proxy.addBeeHiveFX("particles/poison", housing.getWorld(), housing.getXCoord(), housing.getYCoord(),
housing.getZCoord(), 0xffffff, area[0], area[1], area[2]);
return storedData;
}
}
@@ -0,0 +1,67 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.apiculture.items.ItemArmorApiarist;
import forestry.core.utils.DamageSourceForestry;
public class AlleleEffectMisanthrope extends AlleleEffectThrottled {
public static DamageSource damageSourceBeeEnd = new DamageSourceForestry("bee.end");
public AlleleEffectMisanthrope(String uid) {
super(uid, "misanthrope", true, 20, false, false);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
if (isHalted(storedData, housing))
return storedData;
AxisAlignedBB beatifyBox = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = housing.getWorld().getEntitiesWithinAABB(EntityPlayer.class, beatifyBox);
for (Object obj : list) {
EntityPlayer player = (EntityPlayer) obj;
int damage = 4;
// Players are not attacked if they wear a full set of apiarist's
// armor.
int count = ItemArmorApiarist.wearsItems(player, getUID(), true);
// Full set, no damage/effect
if (count > 3)
continue;
else if (count > 2)
damage = 1;
else if (count > 1)
damage = 2;
else if (count > 0)
damage = 3;
player.attackEntityFrom(damageSourceBeeEnd, damage);
}
return storedData;
}
}
@@ -0,0 +1,72 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.world.World;
import forestry.api.apiculture.IAlleleBeeEffect;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.core.genetics.Allele;
import forestry.plugins.PluginApiculture;
public class AlleleEffectNone extends Allele implements IAlleleBeeEffect {
public AlleleEffectNone(String uid) {
super(uid, true);
}
@Override
public IEffectData validateStorage(IEffectData storedData) {
return null;
}
@Override
public boolean isCombinable() {
return false;
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
return doEffect(genome, storedData, housing.getWorld(), housing.getBiomeId(), housing.getXCoord(), housing.getYCoord(), housing.getZCoord());
}
protected IEffectData doEffect(IBeeGenome genome, IEffectData storedData, World world, int biomeid, int x, int y, int z) {
return storedData;
}
@Override
public String getName() {
return "None";
}
@Override
public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
int[] area = genome.getTerritory();
area[0] *= housing.getTerritoryModifier(genome, 1f);
area[1] *= housing.getTerritoryModifier(genome, 1f);
area[2] *= housing.getTerritoryModifier(genome, 1f);
if (area[0] < 1)
area[0] = 1;
if (area[1] < 1)
area[1] = 1;
if (area[2] < 1)
area[2] = 1;
PluginApiculture.proxy.addBeeHiveFX("particles/swarm_bee", housing.getWorld(), housing.getXCoord(), housing.getYCoord(),
housing.getZCoord(), genome.getPrimary().getIconColour(0), area[0], area[1], area[2]);
return storedData;
}
}
@@ -0,0 +1,53 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.AxisAlignedBB;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
public class AlleleEffectPotion extends AlleleEffectThrottled {
private int potionId = 0;
private final int duration;
public AlleleEffectPotion(String uid, String name, boolean isDominant, Potion potion, int duration, boolean requiresWorking) {
super(uid, name, isDominant, 200, requiresWorking, false);
potionId = potion.getId();
this.duration = duration;
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
if (isHalted(storedData, housing))
return storedData;
AxisAlignedBB beatifyBox = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = housing.getWorld().getEntitiesWithinAABB(EntityPlayer.class, beatifyBox);
for (Object obj : list) {
EntityPlayer player = (EntityPlayer) obj;
player.addPotionEffect(new PotionEffect(potionId, duration, 0));
}
return storedData;
}
}
@@ -0,0 +1,125 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.apiculture.gadgets.BlockAlveary;
import forestry.apiculture.gadgets.TileAlveary;
import forestry.apiculture.items.ItemArmorApiarist;
import forestry.core.utils.DamageSourceForestry;
import forestry.core.utils.Vect;
public class AlleleEffectRadioactive extends AlleleEffectThrottled {
public static DamageSource damageSourceBeeRadioactive = new DamageSourceForestry("bee.radioactive");
public AlleleEffectRadioactive(String uid) {
super(uid, "radioactive", true, 40, false, true);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
World world = housing.getWorld();
if (isHalted(storedData, housing))
return storedData;
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0] * 2, areaAr[1] * 2, areaAr[2] * 2);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
// Radioactivity hurts players and mobs
Vect min = new Vect(housing.getXCoord() + offset.x, housing.getYCoord() + offset.y, housing.getZCoord() + offset.z);
Vect max = new Vect(housing.getXCoord() + offset.x + area.x, housing.getYCoord() + offset.y + area.y, housing.getZCoord() + offset.z + area.z);
AxisAlignedBB hurtBox = AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
@SuppressWarnings("rawtypes")
List list = housing.getWorld().getEntitiesWithinAABB(EntityLivingBase.class, hurtBox);
for (Object obj : list) {
EntityLivingBase entity = (EntityLivingBase) obj;
int damage = 8;
// Players are not attacked if they wear a full set of apiarist's
// armor.
if (entity instanceof EntityPlayer) {
int count = ItemArmorApiarist.wearsItems((EntityPlayer) entity, getUID(), true);
// Full set, no damage/effect
if (count > 3)
continue;
else if (count > 2)
damage = 1;
else if (count > 1)
damage = 2;
else if (count > 0)
damage = 3;
}
entity.attackEntityFrom(damageSourceBeeRadioactive, damage);
}
Random rand = housing.getWorld().rand;
// Radioactivity destroys environment
for (int i = 0; i < 20; i++) {
Vect randomPos = new Vect(rand.nextInt(area.x), rand.nextInt(area.y), rand.nextInt(area.z));
Vect posBlock = randomPos.add(new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()));
posBlock = posBlock.add(offset);
if(posBlock.y <= 1 || posBlock.y >= housing.getWorld().getActualHeight())
continue;
// Don't destroy ourself and blocks below us.
if (posBlock.x == housing.getXCoord() && posBlock.z == housing.getZCoord() && posBlock.y <= housing.getYCoord())
continue;
if (world.isAirBlock(posBlock.x, posBlock.y, posBlock.z))
continue;
Block block = world.getBlock(posBlock.x, posBlock.y, posBlock.z);
if (block instanceof BlockAlveary)
continue;
TileEntity tile = world.getTileEntity(posBlock.x, posBlock.y, posBlock.z);
if (tile instanceof IBeeHousing)
continue;
if (tile instanceof TileAlveary)
continue;
if (block.getBlockHardness(world, posBlock.x, posBlock.y, posBlock.z) < 0)
continue;
world.setBlockToAir(posBlock.x, posBlock.y, posBlock.z);
break;
}
return storedData;
}
}
@@ -0,0 +1,58 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.util.AxisAlignedBB;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
public class AlleleEffectRepulsion extends AlleleEffectThrottled {
public AlleleEffectRepulsion(String uid) {
super(uid, "repulsion", false, 100, true, true);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
if (isHalted(storedData, housing))
return storedData;
if (housing.getOwnerName() == null)
return storedData;
AxisAlignedBB hurtBox = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = housing.getWorld().getEntitiesWithinAABB(EntityMob.class, hurtBox);
for (Object obj : list) {
EntityMob mob = (EntityMob) obj;
for (Object objT : mob.tasks.taskEntries) {
EntityAITaskEntry task = (EntityAITaskEntry) objT;
if (task.action instanceof AIAvoidPlayers)
return storedData;
}
mob.tasks.addTask(3, new AIAvoidPlayers(mob, 6.0f, 0.25f, 0.3f));
mob.tasks.onUpdateTasks();
}
return storedData;
}
}
@@ -0,0 +1,111 @@
/*******************************************************************************
* 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.genetics;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.boss.EntityDragon;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityBlaze;
import net.minecraft.entity.monster.EntityCaveSpider;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityEnderman;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.core.utils.StackUtils;
import forestry.core.utils.Utils;
public class AlleleEffectResurrection extends AlleleEffectThrottled {
public static class Resurrectable {
public final ItemStack res;
public final Class<? extends EntityLiving> risen;
public Resurrectable(ItemStack res, Class<? extends EntityLiving> risen) {
this.res = res;
this.risen = risen;
}
}
public static List<Resurrectable> getReanimationList() {
ArrayList<Resurrectable> list = new ArrayList<Resurrectable>();
list.add(new Resurrectable(new ItemStack(Items.bone), EntitySkeleton.class));
list.add(new Resurrectable(new ItemStack(Items.arrow), EntitySkeleton.class));
list.add(new Resurrectable(new ItemStack(Items.rotten_flesh), EntityZombie.class));
list.add(new Resurrectable(new ItemStack(Items.blaze_rod), EntityBlaze.class));
return list;
}
public static List<Resurrectable> getResurrectionList() {
ArrayList<Resurrectable> list = new ArrayList<Resurrectable>();
list.add(new Resurrectable(new ItemStack(Items.gunpowder), EntityCreeper.class));
list.add(new Resurrectable(new ItemStack(Items.ender_pearl), EntityEnderman.class));
list.add(new Resurrectable(new ItemStack(Items.string), EntitySpider.class));
list.add(new Resurrectable(new ItemStack(Items.spider_eye), EntitySpider.class));
list.add(new Resurrectable(new ItemStack(Items.string), EntityCaveSpider.class));
list.add(new Resurrectable(new ItemStack(Items.spider_eye), EntityCaveSpider.class));
list.add(new Resurrectable(new ItemStack(Items.ghast_tear), EntityGhast.class));
list.add(new Resurrectable(new ItemStack(Blocks.dragon_egg), EntityDragon.class));
return list;
}
private final List<Resurrectable> resurrectables;
public AlleleEffectResurrection(String uid, String name, List<Resurrectable> resurrectables) {
super(uid, name, true, 40, true, true);
this.resurrectables = resurrectables;
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
if (isHalted(storedData, housing))
return storedData;
AxisAlignedBB bounding = getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = housing.getWorld().getEntitiesWithinAABB(EntityItem.class, bounding);
if (list.size() > 0)
Collections.shuffle(resurrectables);
for (Object obj : list) {
EntityItem item = (EntityItem) obj;
if (item.isDead)
continue;
ItemStack contained = item.getEntityItem();
for (Resurrectable entry : resurrectables)
if (StackUtils.isIdenticalItem(entry.res, contained)) {
Utils.spawnEntity(housing.getWorld(), entry.risen, item.posX, item.posY, item.posZ);
contained.stackSize--;
if (contained.stackSize <= 0)
item.setDead();
break;
}
}
return storedData;
}
}
@@ -0,0 +1,82 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.init.Blocks;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.util.ForgeDirection;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.core.EnumTemperature;
import forestry.api.genetics.IEffectData;
import forestry.core.proxy.Proxies;
import forestry.core.utils.Vect;
public class AlleleEffectSnowing extends AlleleEffectThrottled {
public AlleleEffectSnowing(String uid) {
super(uid, "snowing", false, 20, true, true);
}
@Override
public IEffectData doEffect(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
World world = housing.getWorld();
if (isHalted(storedData, housing))
return storedData;
EnumTemperature temp = EnumTemperature.getFromValue(BiomeGenBase.getBiome(housing.getBiomeId()).temperature);
switch (temp) {
case HELLISH:
case HOT:
case WARM:
return storedData;
default:
}
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
for (int i = 0; i < 1; i++) {
Vect randomPos = new Vect(world.rand.nextInt(area.x), world.rand.nextInt(area.y), world.rand.nextInt(area.z));
Vect posBlock = randomPos.add(new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()));
posBlock = posBlock.add(offset);
// Put snow on the ground
if (!world.isSideSolid(posBlock.x, posBlock.y - 1, posBlock.z, ForgeDirection.UP, false))
continue;
if (!world.isAirBlock(posBlock.x, posBlock.y, posBlock.z))
continue;
Proxies.common.setBlockWithNotify(world, posBlock.x, posBlock.y, posBlock.z, Blocks.snow_layer);
}
return storedData;
}
@Override
public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
if (housing.getWorld().rand.nextInt(3) == 0) {
int[] area = getModifiedArea(genome, housing);
Proxies.render.addSnowFX(housing.getWorld(), housing.getXCoord(), housing.getYCoord(), housing.getZCoord(), genome.getPrimary().getIconColour(0), area[0], area[1], area[2]);
}
return storedData;
}
}
@@ -0,0 +1,117 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.util.AxisAlignedBB;
import forestry.api.apiculture.IAlleleBeeEffect;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IEffectData;
import forestry.core.EnumErrorCode;
import forestry.core.genetics.Allele;
import forestry.core.genetics.EffectData;
import forestry.core.utils.StringUtil;
import forestry.core.utils.Vect;
import forestry.plugins.PluginApiculture;
public abstract class AlleleEffectThrottled extends Allele implements IAlleleBeeEffect {
private final String name;
private boolean isCombinable = false;
private final int throttle;
private boolean requiresWorkingQueen = false;
public AlleleEffectThrottled(String uid, String name, boolean isDominant, int throttle, boolean requiresWorking, boolean isCombinable) {
super(uid, isDominant);
this.name = "apiculture.effect." + name;
this.throttle = throttle;
this.isCombinable = isCombinable;
this.requiresWorkingQueen = requiresWorking;
}
@Override
public String getName() {
return StringUtil.localize(name);
}
public int getThrottle() {
return throttle;
}
@Override
public boolean isCombinable() {
return isCombinable;
}
@Override
public IEffectData validateStorage(IEffectData storedData) {
if (storedData instanceof EffectData)
return storedData;
return new EffectData(1, 0);
}
public boolean isHalted(IEffectData storedData, IBeeHousing housing) {
if (requiresWorkingQueen && housing.getErrorOrdinal() != EnumErrorCode.OK.ordinal())
return true;
int throttle = storedData.getInteger(0);
throttle++;
storedData.setInteger(0, throttle);
if (throttle < getThrottle())
return true;
// Reset since we are done throttling.
storedData.setInteger(0, 0);
return false;
}
@Override
public IEffectData doFX(IBeeGenome genome, IEffectData storedData, IBeeHousing housing) {
int[] area = getModifiedArea(genome, housing);
PluginApiculture.proxy.addBeeHiveFX("particles/swarm_bee", housing.getWorld(), housing.getXCoord(), housing.getYCoord(),
housing.getZCoord(), genome.getPrimary().getIconColour(0), area[0], area[1], area[2]);
return storedData;
}
protected int[] getModifiedArea(IBeeGenome genome, IBeeHousing housing) {
int[] area = genome.getTerritory();
area[0] *= housing.getTerritoryModifier(genome, 1f) * 3;
area[1] *= housing.getTerritoryModifier(genome, 1f) * 3;
area[2] *= housing.getTerritoryModifier(genome, 1f) * 3;
if (area[0] < 1)
area[0] = 1;
if (area[1] < 1)
area[1] = 1;
if (area[2] < 1)
area[2] = 1;
return area;
}
protected AxisAlignedBB getBounding(IBeeGenome genome, IBeeHousing housing, float modifier) {
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(modifier);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
// Radioactivity hurts players and mobs
Vect min = new Vect(housing.getXCoord() + offset.x, housing.getYCoord() + offset.y, housing.getZCoord() + offset.z);
Vect max = new Vect(housing.getXCoord() + offset.x + area.x, housing.getYCoord() + offset.y + area.y, housing.getZCoord() + offset.z + area.z);
return AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
}
}
@@ -0,0 +1,40 @@
/*******************************************************************************
* 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.genetics;
import forestry.api.genetics.IAlleleFlowers;
import forestry.api.genetics.IFlowerProvider;
import forestry.core.genetics.Allele;
public class AlleleFlowers extends Allele implements IAlleleFlowers {
IFlowerProvider provider;
public AlleleFlowers(String uid, IFlowerProvider provider) {
this(uid, provider, false);
}
public AlleleFlowers(String uid, IFlowerProvider provider, boolean isDominant) {
super(uid, isDominant);
this.provider = provider;
}
@Override
public IFlowerProvider getProvider() {
return provider;
}
@Override
public String getName() {
return getProvider().getDescription();
}
}
@@ -0,0 +1,115 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import com.mojang.authlib.GameProfile;
import forestry.api.apiculture.IApiaristTracker;
import forestry.api.genetics.IBreedingTracker;
import forestry.api.genetics.IIndividual;
import forestry.core.genetics.BreedingTracker;
import forestry.plugins.PluginApiculture;
public class ApiaristTracker extends BreedingTracker implements IApiaristTracker {
public ApiaristTracker(String s) {
this(s, null);
}
public ApiaristTracker(String s, GameProfile player) {
super(s, player);
}
private int queensTotal = 0;
private int dronesTotal = 0;
private int princessesTotal = 0;
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
queensTotal = nbttagcompound.getInteger("QueensTotal");
princessesTotal = nbttagcompound.getInteger("PrincessesTotal");
dronesTotal = nbttagcompound.getInteger("DronesTotal");
super.readFromNBT(nbttagcompound);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("QueensTotal", queensTotal);
nbttagcompound.setInteger("PrincessesTotal", princessesTotal);
nbttagcompound.setInteger("DronesTotal", dronesTotal);
super.writeToNBT(nbttagcompound);
}
@Override
public void registerPickup(IIndividual individual) {
if(!individual.getGenome().getPrimary().getRoot().getUID().equals(BeeHelper.UID))
return;
if(!individual.isPureBred(0))
return;
if(PluginApiculture.beeInterface.getCombinations(individual.getGenome().getPrimary()).size() > 0)
return;
registerSpecies(individual.getGenome().getPrimary());
}
@Override
public void registerQueen(IIndividual bee) {
queensTotal++;
}
@Override
public int getQueenCount() {
return queensTotal;
}
@Override
public void registerPrincess(IIndividual bee) {
princessesTotal++;
registerBirth(bee);
}
@Override
public int getPrincessCount() {
return princessesTotal;
}
@Override
public void registerDrone(IIndividual bee) {
dronesTotal++;
registerBirth(bee);
}
@Override
public int getDroneCount() {
return dronesTotal;
}
@Override
protected IBreedingTracker getCommonTracker(EntityPlayer player) {
return PluginApiculture.beeInterface.getBreedingTracker(player.worldObj, null);
}
@Override
protected String getPacketTag() {
return BeeHelper.UID;
}
}
+716
View File
@@ -0,0 +1,716 @@
/*******************************************************************************
* 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.genetics;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.BiomeDictionary;
import forestry.api.apiculture.EnumBeeChromosome;
import forestry.api.apiculture.IAlleleBeeEffect;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IApiaristTracker;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeMutation;
import forestry.api.apiculture.IBeekeepingMode;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.EnumTolerance;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IChromosome;
import forestry.api.genetics.IEffectData;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.IGenome;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IPollinatable;
import forestry.core.EnumErrorCode;
import forestry.core.config.Defaults;
import forestry.core.genetics.Chromosome;
import forestry.core.genetics.GenericRatings;
import forestry.core.genetics.IndividualLiving;
import forestry.core.proxy.Proxies;
import forestry.core.utils.StackUtils;
import forestry.core.utils.StringUtil;
import forestry.core.utils.Utils;
import forestry.core.utils.Vect;
import forestry.plugins.PluginApiculture;
public class Bee extends IndividualLiving implements IBee {
public IBeeGenome genome;
public IBeeGenome mate;
/* CONSTRUCTOR */
public Bee(NBTTagCompound nbttagcompound) {
readFromNBT(nbttagcompound);
}
public Bee(World world, IBeeGenome genome, IBee mate) {
this(world, genome);
this.mate = mate.getGenome();
this.isIrregularMating = mate.isNatural() != this.isNatural;
}
public Bee(IBeeGenome genome, IBee mate) {
this(genome);
this.mate = mate.getGenome();
this.isIrregularMating = mate.isNatural() != this.isNatural;
}
public Bee(World world, IBeeGenome genome) {
this(world, genome, true, 0);
}
public Bee(IBeeGenome genome) {
this(genome, true, 0);
}
public Bee(World world, IBeeGenome genome, boolean isNatural, int generation) {
super(genome.getLifespan(), isNatural, generation);
this.genome = genome;
}
public Bee(IBeeGenome genome, boolean isNatural, int generation) {
super(genome.getLifespan(), isNatural, generation);
this.genome = genome;
}
/* SAVING & LOADING */
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
if (nbttagcompound == null) {
this.genome = PluginApiculture.beeInterface.templateAsGenome(BeeTemplates.getForestTemplate());
return;
}
super.readFromNBT(nbttagcompound);
if (nbttagcompound.hasKey("Genome"))
genome = new BeeGenome(nbttagcompound.getCompoundTag("Genome"));
else
genome = PluginApiculture.beeInterface.templateAsGenome(BeeTemplates.getForestTemplate());
if (nbttagcompound.hasKey("Mate"))
mate = new BeeGenome(nbttagcompound.getCompoundTag("Mate"));
}
@Override
public void mate(IIndividual individual) {
if(!(individual instanceof IBee))
return;
IBee drone = (IBee)individual;
mate = drone.getGenome();
this.isIrregularMating = drone.isNatural() != this.isNatural;
}
/* EFFECTS */
@Override
public IEffectData[] doEffect(IEffectData[] storedData, IBeeHousing housing) {
IAlleleBeeEffect effect = genome.getEffect();
if (effect == null)
return null;
storedData[0] = doEffect(effect, storedData[0], housing);
// Return here if the primary can already not be combined
if (!effect.isCombinable())
return storedData;
IAlleleBeeEffect secondary = (IAlleleBeeEffect) genome.getInactiveAllele(EnumBeeChromosome.EFFECT.ordinal());
if (!secondary.isCombinable())
return storedData;
storedData[1] = doEffect(secondary, storedData[1], housing);
return storedData;
}
private IEffectData doEffect(IAlleleBeeEffect effect, IEffectData storedData, IBeeHousing housing) {
storedData = effect.validateStorage(storedData);
return effect.doEffect(genome, storedData, housing);
}
@Override
public IEffectData[] doFX(IEffectData[] storedData, IBeeHousing housing) {
IAlleleBeeEffect effect = genome.getEffect();
if (effect == null)
return null;
storedData[0] = doFX(effect, storedData[0], housing);
// Return here if the primary can already not be combined
if (!effect.isCombinable())
return storedData;
IAlleleBeeEffect secondary = (IAlleleBeeEffect) genome.getInactiveAllele(EnumBeeChromosome.EFFECT.ordinal());
if (!secondary.isCombinable())
return storedData;
storedData[1] = doFX(secondary, storedData[1], housing);
return storedData;
}
private IEffectData doFX(IAlleleBeeEffect effect, IEffectData storedData, IBeeHousing housing) {
return effect.doFX(genome, storedData, housing);
}
// / INFORMATION
@Override
public IBeeGenome getGenome() {
return genome;
}
@Override
public IBeeGenome getMate() {
return mate;
}
@Override
public IBee copy() {
NBTTagCompound nbttagcompound = new NBTTagCompound();
this.writeToNBT(nbttagcompound);
return new Bee(nbttagcompound);
}
@Override
public boolean canSpawn() {
return mate != null;
}
@Override
public int isWorking(IBeeHousing housing) {
World world = housing.getWorld();
// / Rain needs tolerant flyers
if (world.isRaining() && !genome.getTolerantFlyer() && housing.getHumidity() != EnumHumidity.ARID && !housing.isSealed())
return EnumErrorCode.ISRAINING.ordinal();
// / Night or darkness requires nocturnal species
if(world.isDaytime()) {
if(!canWorkDuringDay())
return EnumErrorCode.NOTNIGHT.ordinal();
} else if (!canWorkAtNight() && !housing.isSelfLighted())
return EnumErrorCode.NOTDAY.ordinal();
if (world.getBlockLightValue(housing.getXCoord(), housing.getYCoord() + 2, housing.getZCoord()) > Defaults.APIARY_MIN_LEVEL_LIGHT) {
if(!canWorkDuringDay())
return EnumErrorCode.NOTGLOOMY.ordinal();
} else if(!canWorkAtNight() && !housing.isSelfLighted())
return EnumErrorCode.NOTLUCID.ordinal();
// / No sky, except if in hell
BiomeGenBase biome = BiomeGenBase.getBiome(housing.getBiomeId());
if(biome == null)
return EnumErrorCode.NOSKY.ordinal();
if (!BiomeDictionary.isBiomeOfType(biome, BiomeDictionary.Type.NETHER) && !world.canBlockSeeTheSky(housing.getXCoord(), housing.getYCoord() + 3, housing.getZCoord())
&& !genome.getCaveDwelling() && !housing.isSunlightSimulated())
return EnumErrorCode.NOSKY.ordinal();
// / And finally biome check
if (!checkBiomeHazard(world, housing.getTemperature(), housing.getHumidity(), housing.getXCoord(), housing.getYCoord(), housing.getZCoord()))
return EnumErrorCode.INVALIDBIOME.ordinal();
return EnumErrorCode.OK.ordinal();
}
private boolean canWorkAtNight() {
return genome.getPrimary().isNocturnal() || genome.getNocturnal();
}
private boolean canWorkDuringDay() {
return !genome.getPrimary().isNocturnal() || genome.getNocturnal();
}
private boolean checkBiomeHazard(World world, EnumTemperature temperature, EnumHumidity humidity, int x, int y, int z) {
return AlleleManager.climateHelper.isWithinLimits(temperature, humidity,
genome.getPrimary().getTemperature(), genome.getToleranceTemp(),
genome.getPrimary().getHumidity(), genome.getToleranceHumid());
}
@Override
public boolean hasFlower(IBeeHousing housing) {
IFlowerProvider provider = genome.getFlowerProvider();
Vect coords = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord());
Vect posCurrent = new Vect(0, 0, 0);
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(housing.getTerritoryModifier(genome, 1f));
if (area.x < 1)
area.x = 1;
if (area.y < 1)
area.y = 1;
if (area.z < 1)
area.z = 1;
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
boolean hasFlower = false;
while (advancePosition(posCurrent, area)) {
Vect posBlock = posCurrent.add(coords);
posBlock = posBlock.add(offset);
if (provider.isAcceptedFlower(housing.getWorld(), this, posBlock.x, posBlock.y, posBlock.z)) {
hasFlower = true;
break;
}
}
return hasFlower;
}
private boolean advancePosition(Vect posCurrent, Vect area) {
// Increment z first until end reached
if (posCurrent.z < area.z - 1)
posCurrent.z++;
else {
posCurrent.z = 0;
if (posCurrent.x < area.x - 1)
posCurrent.x++;
else {
posCurrent.x = 0;
if (posCurrent.y < area.y - 1)
posCurrent.y++;
else
return false;
}
}
return true;
}
@Override
public ArrayList<Integer> getSuitableBiomeIds() {
EnumTemperature temperature = genome.getPrimary().getTemperature();
EnumTolerance temperatureTolerance = genome.getToleranceTemp();
Collection<EnumTemperature> toleratedTemperatures = AlleleManager.climateHelper.getToleratedTemperature(temperature, temperatureTolerance);
EnumHumidity humidity = genome.getPrimary().getHumidity();
EnumTolerance humidityTolerance = genome.getToleranceHumid();
Collection<EnumHumidity> toleratedHumidities = AlleleManager.climateHelper.getToleratedHumidity(humidity, humidityTolerance);
ArrayList<Integer> biomeIdsTemp = new ArrayList<Integer>();
for (EnumTemperature temp : toleratedTemperatures)
biomeIdsTemp.addAll(EnumTemperature.getBiomeIds(temp));
ArrayList<Integer> biomeIdsHumid = new ArrayList<Integer>();
for (EnumHumidity humid : toleratedHumidities)
biomeIdsHumid.addAll(EnumHumidity.getBiomeIds(humid));
biomeIdsTemp.retainAll(biomeIdsHumid);
return biomeIdsTemp;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void addTooltip(List list) {
// No info 4 u!
if (!isAnalyzed) {
list.add("<" + StringUtil.localize("gui.unknown") + ">");
return;
}
// You analyzed it? Juicy tooltip coming up!
IAlleleBeeSpecies primary = genome.getPrimary();
IAlleleBeeSpecies secondary = genome.getSecondary();
if (!isPureBred(EnumBeeChromosome.SPECIES.ordinal()))
list.add("\u00A79" + primary.getName() + StringUtil.localize("bees.hyphen.adj.add") + "-" + secondary.getName()
+ StringUtil.localize("bees.hybrid.adj.add") + " " + StringUtil.localize("gui.hybrid"));
list.add(genome.getActiveAllele(EnumBeeChromosome.SPEED.ordinal()).getName() + " " + StringUtil.localize("gui.worker"));
list.add(genome.getActiveAllele(EnumBeeChromosome.LIFESPAN.ordinal()).getName() + " " + StringUtil.localize("gui.life"));
list.add("\u00A7aT: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getTemperature()) + " / "
+ StringUtil.capitalize(genome.getToleranceTemp().name()));
list.add("\u00A7aH: " + AlleleManager.climateHelper.toDisplay(genome.getPrimary().getHumidity()) + " / "
+ StringUtil.capitalize(genome.getToleranceHumid().name()));
list.add(StringUtil.localize(genome.getFlowerProvider().getDescription()));
if (genome.getNocturnal())
list.add("\u00A7c" + GenericRatings.rateActivityTime(genome.getNocturnal(), false));
}
@Override
public void age(World world, float housingLifespanModifier) {
IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(world);
float finalModifier = housingLifespanModifier * mode.getLifespanModifier(genome, mate, housingLifespanModifier);
super.age(world, finalModifier);
}
// / PRODUCTION
@Override
public ItemStack[] getProduceList() {
ArrayList<ItemStack> products = new ArrayList<ItemStack>();
IAlleleBeeSpecies primary = genome.getPrimary();
IAlleleBeeSpecies secondary = genome.getSecondary();
products.addAll(primary.getProducts().keySet());
Set<ItemStack> secondaryProducts = secondary.getProducts().keySet();
// Remove duplicates
for (ItemStack second : secondaryProducts) {
boolean skip = false;
for (ItemStack compare : products)
if (second.isItemEqual(compare)) {
skip = true;
break;
}
if (!skip)
products.add(second);
}
return products.toArray(new ItemStack[0]);
}
@Override
public ItemStack[] getSpecialtyList() {
return genome.getPrimary().getSpecialty().keySet().toArray(new ItemStack[0]);
}
@Override
public ItemStack[] produceStacks(IBeeHousing housing) {
if (!hasFlower(housing))
return null;
if (housing == null) {
Proxies.log.warning("Failed to produce in an apiary because the beehousing was null.");
return null;
}
IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(housing.getWorld());
if (mode == null) {
Proxies.log.warning("Failed to produce in an apiary because the beekeeping mode was null.");
return null;
}
ArrayList<ItemStack> products = new ArrayList<ItemStack>();
IAlleleBeeSpecies primary = genome.getPrimary();
IAlleleBeeSpecies secondary = genome.getSecondary();
// All work and no play makes queen a dull girl.
if(mode.isOverworked(this, housing))
setIsNatural(false);
// Bee genetic speed * beehousing * beekeeping mode
float speed = genome.getSpeed() * housing.getProductionModifier(genome, 1f) * mode.getProductionModifier(genome, 1f);
// / Primary Products
for (Map.Entry<ItemStack, Integer> entry : primary.getProducts().entrySet())
if (housing.getWorld().rand.nextInt(100) < entry.getValue() * speed)
products.add(entry.getKey().copy());
// / Secondary Products
for (Map.Entry<ItemStack, Integer> entry : secondary.getProducts().entrySet())
if (housing.getWorld().rand.nextInt(100) < Math.round(entry.getValue() / 2) * speed)
products.add(entry.getKey().copy());
// We are done if the we are not jubilant.
if (!primary.isJubilant(genome, housing) || !secondary.isJubilant(genome, housing))
return products.toArray(StackUtils.EMPTY_STACK_ARRAY);
// / Specialty products
for (Map.Entry<ItemStack, Integer> entry : primary.getSpecialty().entrySet())
if (housing.getWorld().rand.nextInt(100) < entry.getValue() * speed)
products.add(entry.getKey().copy());
return genome.getFlowerProvider().affectProducts(housing.getWorld(), this, housing.getXCoord(), housing.getYCoord(), housing.getZCoord(),
products.toArray(StackUtils.EMPTY_STACK_ARRAY));
}
/* REPRODUCTION */
@Override
public IBee spawnPrincess(IBeeHousing housing) {
// We need a mated queen to produce offspring.
if (mate == null)
return null;
// Fatigued queens do not produce princesses.
if (PluginApiculture.beeInterface.getBeekeepingMode(housing.getWorld()).isFatigued(this, housing))
return null;
return createOffspring(housing, getGeneration() + 1);
}
@Override
public IBee[] spawnDrones(IBeeHousing housing) {
World world = housing.getWorld();
// We need a mated queen to produce offspring.
if (mate == null)
return null;
ArrayList<IBee> bees = new ArrayList<IBee>();
int toCreate = PluginApiculture.beeInterface.getBeekeepingMode(world).getFinalFertility(this, world, housing.getXCoord(), housing.getYCoord(),
housing.getZCoord());
if (toCreate <= 0)
toCreate = 1;
for (int i = 0; i < toCreate; i++) {
IBee offspring = createOffspring(housing, -1);
if (offspring != null) {
offspring.setIsNatural(true);
bees.add(offspring);
}
}
if (bees.size() > 0)
return bees.toArray(new IBee[0]);
else
return null;
}
private IBee createOffspring(IBeeHousing housing, int generation) {
World world = housing.getWorld();
IChromosome[] chromosomes = new IChromosome[genome.getChromosomes().length];
IChromosome[] parent1 = genome.getChromosomes();
IChromosome[] parent2 = mate.getChromosomes();
// Check for mutation. Replace one of the parents with the mutation
// template if mutation occured.
IChromosome[] mutated1 = mutateSpecies(housing, genome, mate);
if (mutated1 != null)
parent1 = mutated1;
IChromosome[] mutated2 = mutateSpecies(housing, mate, genome);
if (mutated2 != null)
parent2 = mutated2;
for (int i = 0; i < parent1.length; i++)
if (parent1[i] != null && parent2[i] != null)
chromosomes[i] = Chromosome.inheritChromosome(world.rand, parent1[i], parent2[i]);
IBeekeepingMode mode = PluginApiculture.beeInterface.getBeekeepingMode(world);
IBee offspring = new Bee(world, new BeeGenome(chromosomes), mode.isNaturalOffspring(this), generation);
/* Disabling the mutation rate nerf
// All mutation and no play makes queen a dull girl.
if(mode.isDegenerating(this, offspring, housing))
offspring.setIsNatural(false);*/
return offspring;
}
private IChromosome[] mutateSpecies(IBeeHousing housing, IGenome genomeOne, IGenome genomeTwo) {
World world = housing.getWorld();
IChromosome[] parent1 = genomeOne.getChromosomes();
IChromosome[] parent2 = genomeTwo.getChromosomes();
IGenome genome0;
IGenome genome1;
IAllele allele0;
IAllele allele1;
if (world.rand.nextBoolean()) {
allele0 = parent1[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
allele1 = parent2[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
genome0 = genomeOne;
genome1 = genomeTwo;
} else {
allele0 = parent2[EnumBeeChromosome.SPECIES.ordinal()].getPrimaryAllele();
allele1 = parent1[EnumBeeChromosome.SPECIES.ordinal()].getSecondaryAllele();
genome0 = genomeTwo;
genome1 = genomeOne;
}
for (IBeeMutation mutation : PluginApiculture.beeInterface.getMutations(true)) {
float chance = 0;
if ((chance = mutation.getChance(housing, allele0, allele1, genome0, genome1)) > 0)
if (world.rand.nextFloat()*100 < chance) {
IApiaristTracker breedingTracker = PluginApiculture.beeInterface.getBreedingTracker(world, housing.getOwnerName());
breedingTracker.registerMutation(mutation);
return PluginApiculture.beeInterface.templateAsChromosomes(mutation.getTemplate());
}
}
return null;
}
/* FLOWERS */
@Override
public IIndividual retrievePollen(IBeeHousing housing) {
int chance = (int) (genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f));
// Correct speed
if (housing.getWorld().rand.nextInt(100) >= chance)
return null;
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(housing.getTerritoryModifier(genome, 1f)).multiply(3.0f);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
if (area.x < 1)
area.x = 1;
if (area.y < 1)
area.y = 1;
if (area.z < 1)
area.z = 1;
// We have up to ten attempts
for (int i = 0; i < 20; i++) {
Vect randomPos = new Vect(housing.getWorld().rand.nextInt(area.x), housing.getWorld().rand.nextInt(area.y), housing.getWorld().rand.nextInt(area.z));
Vect posBlock = randomPos.add(new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()));
posBlock = posBlock.add(offset);
TileEntity tile = housing.getWorld().getTileEntity(posBlock.x, posBlock.y, posBlock.z);
if (!(tile instanceof IPollinatable)) {
if (housing.getWorld().isAirBlock(posBlock.x, posBlock.y, posBlock.z))
continue;
// Test for ersatz genomes
for (Map.Entry<ItemStack, IIndividual> entry : AlleleManager.ersatzSpecimen.entrySet()) {
if (!StackUtils.equals(housing.getWorld().getBlock(posBlock.x, posBlock.y, posBlock.z), entry.getKey()))
continue;
if (entry.getKey().getItemDamage() != housing.getWorld().getBlockMetadata(posBlock.x, posBlock.y, posBlock.z))
continue;
// We matched, return ersatz genome
return entry.getValue().copy();
}
continue;
}
IPollinatable pitcher = (IPollinatable) tile;
if (!genome.getFlowerProvider().isAcceptedPollinatable(housing.getWorld(), pitcher))
continue;
IIndividual pollen = pitcher.getPollen();
if (pollen != null)
return pollen;
}
return null;
}
@Override
public boolean pollinateRandom(IBeeHousing housing, IIndividual pollen) {
int chance = (int) (genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f));
// Correct speed
if (housing.getWorld().rand.nextInt(100) >= chance)
return false;
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(housing.getTerritoryModifier(genome, 1f)).multiply(3.0f);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 4), -Math.round(area.z / 2));
if (area.x < 1)
area.x = 1;
if (area.y < 1)
area.y = 1;
if (area.z < 1)
area.z = 1;
// We have up to ten attempts
for (int i = 0; i < 30; i++) {
Vect randomPos = new Vect(housing.getWorld().rand.nextInt(area.x), housing.getWorld().rand.nextInt(area.y), housing.getWorld().rand.nextInt(area.z));
Vect posBlock = randomPos.add(new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()));
posBlock = posBlock.add(offset);
IPollinatable receiver = Utils.getOrCreatePollinatable(housing.getOwnerName(), housing.getWorld(), posBlock.x, posBlock.y, posBlock.z);
if(receiver == null)
continue;
if (!genome.getFlowerProvider().isAcceptedPollinatable(housing.getWorld(), receiver))
continue;
if (!receiver.canMateWith(pollen))
continue;
receiver.mateWith(pollen);
return true;
}
return false;
}
@Override
public void plantFlowerRandom(IBeeHousing housing) {
int chance = (int) (genome.getFlowering() * housing.getFloweringModifier(getGenome(), 1f));
// Correct speed
if (housing.getWorld().rand.nextInt(100) >= chance)
return;
// Gather required info
IFlowerProvider provider = genome.getFlowerProvider();
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(housing.getTerritoryModifier(genome, 1f)).multiply(3.0f);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 4), -Math.round(area.z / 2));
if (area.x < 1)
area.x = 1;
if (area.y < 1)
area.y = 1;
if (area.z < 1)
area.z = 1;
// We have up to ten attempts
for (int i = 0; i < 10; i++) {
Vect randomPos = new Vect(housing.getWorld().rand.nextInt(area.x), housing.getWorld().rand.nextInt(area.y), housing.getWorld().rand.nextInt(area.z));
Vect posBlock = randomPos.add(new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord()));
posBlock = posBlock.add(offset);
if (provider.growFlower(housing.getWorld(), this, posBlock.x, posBlock.y, posBlock.z))
break;
}
}
}
+148
View File
@@ -0,0 +1,148 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.nbt.NBTTagCompound;
import forestry.api.apiculture.EnumBeeChromosome;
import forestry.api.apiculture.IAlleleBeeEffect;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.genetics.EnumTolerance;
import forestry.api.genetics.IAlleleFloat;
import forestry.api.genetics.IAlleleFlowers;
import forestry.api.genetics.IAlleleInteger;
import forestry.api.genetics.IChromosome;
import forestry.api.genetics.IFlowerProvider;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.genetics.AlleleArea;
import forestry.core.genetics.AlleleBoolean;
import forestry.core.genetics.AlleleTolerance;
import forestry.core.genetics.Genome;
import forestry.core.utils.Vect;
import forestry.plugins.PluginApiculture;
public class BeeGenome extends Genome implements IBeeGenome {
/**
* 0 - Species (determines product)
*
* 1 - Speed
*
* 2 - Lifespan
*
* 3 - Fertility (Maximum number of offspring)
*
* 4 - Preferred temperature Icy: Snow biomes Cold: Tundra/Steppe, Extreme Mountains/Hills? Normal: Plains, Forests, Mountains Hot: Desert Hellish: Nether
*
* 5 - Temperature tolerance (Range +/-)
*
* 6 - Nocturnal
*
* 7 - Preferred humidity (Arid - Normal - Damp)
*
* 8 - Humidity tolerance (Range +/-)
*
* 9 - Flight interference tolerance (stuff falling from the sky/other hindrances -> tolerates dampness + flight interference tolerance => rain resistance)
*
* 10 - Cave dwelling
*
* 11 - Required flowers
*
* 12 - Flower plant chance
*
* 13 - Territory
*/
/* CONSTRUCTOR */
public BeeGenome(NBTTagCompound nbttagcompound) {
super(nbttagcompound);
}
public BeeGenome(IChromosome[] chromosomes) {
super(chromosomes);
}
// / INFORMATION RETRIEVAL
@Override
public IAlleleBeeSpecies getPrimary() {
return (IAlleleBeeSpecies) getActiveAllele(EnumBeeChromosome.SPECIES.ordinal());
}
@Override
public IAlleleBeeSpecies getSecondary() {
return (IAlleleBeeSpecies) getInactiveAllele(EnumBeeChromosome.SPECIES.ordinal());
}
@Override
public float getSpeed() {
return ((IAlleleFloat) getActiveAllele(EnumBeeChromosome.SPEED.ordinal())).getValue();
}
@Override
public int getLifespan() {
return ((IAlleleInteger) getActiveAllele(EnumBeeChromosome.LIFESPAN.ordinal())).getValue();
}
@Override
public int getFertility() {
return ((IAlleleInteger) getActiveAllele(EnumBeeChromosome.FERTILITY.ordinal())).getValue();
}
@Override
public EnumTolerance getToleranceTemp() {
return ((AlleleTolerance) getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal())).getValue();
}
@Override
public boolean getNocturnal() {
return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.NOCTURNAL.ordinal())).getValue();
}
@Override
public EnumTolerance getToleranceHumid() {
return ((AlleleTolerance) getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal())).getValue();
}
@Override
public boolean getTolerantFlyer() {
return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.TOLERANT_FLYER.ordinal())).getValue();
}
@Override
public boolean getCaveDwelling() {
return ((AlleleBoolean) getActiveAllele(EnumBeeChromosome.CAVE_DWELLING.ordinal())).getValue();
}
@Override
public IFlowerProvider getFlowerProvider() {
return ((IAlleleFlowers) getActiveAllele(EnumBeeChromosome.FLOWER_PROVIDER.ordinal())).getProvider();
}
@Override
public int getFlowering() {
return ((IAlleleInteger) getActiveAllele(EnumBeeChromosome.FLOWERING.ordinal())).getValue();
}
@Override
public int[] getTerritory() {
Vect area = ((AlleleArea) getActiveAllele(EnumBeeChromosome.TERRITORY.ordinal())).getArea();
return new int[] { area.x, area.y, area.z };
}
@Override
public IAlleleBeeEffect getEffect() {
return (IAlleleBeeEffect) getActiveAllele(EnumBeeChromosome.EFFECT.ordinal());
}
@Override
public ISpeciesRoot getSpeciesRoot() {
return PluginApiculture.beeInterface;
}
}
+336
View File
@@ -0,0 +1,336 @@
/*******************************************************************************
* 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.genetics;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map.Entry;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import cpw.mods.fml.common.FMLCommonHandler;
import com.mojang.authlib.GameProfile;
import forestry.api.apiculture.EnumBeeChromosome;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IAlvearyComponent;
import forestry.api.apiculture.IApiaristTracker;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeMutation;
import forestry.api.apiculture.IBeeRoot;
import forestry.api.apiculture.IBeekeepingLogic;
import forestry.api.apiculture.IBeekeepingMode;
import forestry.api.core.IStructureLogic;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IChromosomeType;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.IMutation;
import forestry.apiculture.BeekeepingLogic;
import forestry.apiculture.gadgets.StructureLogicAlveary;
import forestry.core.config.ForestryItem;
import forestry.core.genetics.SpeciesRoot;
import forestry.plugins.PluginApiculture;
public class BeeHelper extends SpeciesRoot implements IBeeRoot {
public static int beeSpeciesCount = -1;
public static final String UID = "rootBees";
@Override
public String getUID() {
return UID;
}
@Override
public Class<? extends IIndividual> getMemberClass() {
return IBee.class;
}
@Override
public int getSpeciesCount() {
if (beeSpeciesCount < 0) {
beeSpeciesCount = 0;
Iterator<Entry<String, IAllele> > it = AlleleManager.alleleRegistry.getRegisteredAlleles().entrySet().iterator();
while (it.hasNext()) {
Entry<String, IAllele> entry = it.next();
if (entry.getValue() instanceof IAlleleBeeSpecies)
if (((IAlleleBeeSpecies) entry.getValue()).isCounted())
beeSpeciesCount++;
}
}
return beeSpeciesCount;
}
@Override
public boolean isMember(ItemStack stack) {
return getType(stack) != EnumBeeType.NONE;
}
@Override
public boolean isMember(ItemStack stack, int type) {
return getType(stack).ordinal() == type;
}
@Override
public boolean isMember(IIndividual individual) {
return individual instanceof IBee;
}
@Override
public ItemStack getMemberStack(IIndividual bee, int type) {
if (!isMember(bee))
return null;
Item beeItem = null;
switch (EnumBeeType.VALUES[type]) {
case QUEEN:
beeItem = ForestryItem.beeQueenGE.item();
break;
case PRINCESS:
beeItem = ForestryItem.beePrincessGE.item();
break;
case DRONE:
beeItem = ForestryItem.beeDroneGE.item();
break;
case LARVAE:
beeItem = ForestryItem.beeLarvaeGE.item();
break;
default:
throw new RuntimeException("Cannot instantiate a bee of type " + type);
}
NBTTagCompound nbttagcompound = new NBTTagCompound();
bee.writeToNBT(nbttagcompound);
ItemStack beeStack = new ItemStack(beeItem);
beeStack.setTagCompound(nbttagcompound);
return beeStack;
}
@Override
public EnumBeeType getType(ItemStack stack) {
if (stack == null)
return EnumBeeType.NONE;
if (ForestryItem.beeDroneGE.isItemEqual(stack))
return EnumBeeType.DRONE;
else if (ForestryItem.beePrincessGE.isItemEqual(stack))
return EnumBeeType.PRINCESS;
else if (ForestryItem.beeQueenGE.isItemEqual(stack))
return EnumBeeType.QUEEN;
else if (ForestryItem.beeLarvaeGE.isItemEqual(stack))
return EnumBeeType.LARVAE;
return EnumBeeType.NONE;
}
@Override
public boolean isDrone(ItemStack stack) {
return getType(stack) == EnumBeeType.DRONE;
}
@Override
public boolean isMated(ItemStack stack) {
if (getType(stack) != EnumBeeType.QUEEN)
return false;
IBee bee = getMember(stack);
return bee.getMate() != null;
}
@Override
public IBee getMember(ItemStack stack) {
if (!ForestryItem.beeQueenGE.isItemEqual(stack) && !ForestryItem.beePrincessGE.isItemEqual(stack)
&& !ForestryItem.beeDroneGE.isItemEqual(stack) && !ForestryItem.beeLarvaeGE.isItemEqual(stack))
return null;
return new Bee(stack.getTagCompound());
}
@Override
public IBee getMember(NBTTagCompound compound) {
return new Bee(compound);
}
@Override
public IBee getBee(World world, IBeeGenome genome) {
return new Bee(world, genome);
}
@Override
public IBee getBee(World world, IBeeGenome genome, IBee mate) {
return new Bee(world, genome, mate);
}
/* GENOME CONVERSIONS */
@Override
public IBeeGenome templateAsGenome(IAllele[] template) {
return new BeeGenome(templateAsChromosomes(template));
}
@Override
public IBeeGenome templateAsGenome(IAllele[] templateActive, IAllele[] templateInactive) {
return new BeeGenome(templateAsChromosomes(templateActive, templateInactive));
}
@Override
public IBee templateAsIndividual(IAllele[] template) {
return new Bee(templateAsGenome(template));
}
@Override
public IBee templateAsIndividual(IAllele[] templateActive, IAllele[] templateInactive) {
return new Bee(templateAsGenome(templateActive, templateInactive));
}
/* TEMPLATES */
public static ArrayList<IBee> beeTemplates = new ArrayList<IBee>();
@Override
public ArrayList<IBee> getIndividualTemplates() {
return beeTemplates;
}
@Override
public void registerTemplate(String identifier, IAllele[] template) {
beeTemplates.add(new Bee(PluginApiculture.beeInterface.templateAsGenome(template)));
speciesTemplates.put(identifier, template);
}
@Override
public IAllele[] getDefaultTemplate() {
return BeeTemplates.getDefaultTemplate();
}
/* MUTATIONS */
/**
* List of possible mutations on species alleles.
*/
private static ArrayList<IBeeMutation> beeMutations = new ArrayList<IBeeMutation>();
@Override
public Collection<IBeeMutation> getMutations(boolean shuffle) {
if (shuffle)
Collections.shuffle(beeMutations);
return beeMutations;
}
@Override
public void registerMutation(IMutation mutation) {
if (AlleleManager.alleleRegistry.isBlacklisted(mutation.getTemplate()[0].getUID()))
return;
if (AlleleManager.alleleRegistry.isBlacklisted(mutation.getAllele0().getUID()))
return;
if (AlleleManager.alleleRegistry.isBlacklisted(mutation.getAllele1().getUID()))
return;
beeMutations.add((IBeeMutation) mutation);
}
/* BREEDING MODES */
ArrayList<IBeekeepingMode> beekeepingModes = new ArrayList<IBeekeepingMode>();
public static IBeekeepingMode activeBeekeepingMode;
@Override
public void resetBeekeepingMode() {
activeBeekeepingMode = null;
}
@Override
public ArrayList<IBeekeepingMode> getBeekeepingModes() {
return this.beekeepingModes;
}
@Override
public IBeekeepingMode getBeekeepingMode(World world) {
if (activeBeekeepingMode != null)
return activeBeekeepingMode;
// No beekeeping mode yet, get it.
IApiaristTracker tracker = getBreedingTracker(world, null);
String mode = tracker.getModeName();
if (mode == null || mode.isEmpty())
mode = PluginApiculture.beekeepingMode;
setBeekeepingMode(world, mode);
FMLCommonHandler.instance().getFMLLogger().debug("Set beekeeping mode for a world to " + mode);
return activeBeekeepingMode;
}
@Override
public void registerBeekeepingMode(IBeekeepingMode mode) {
beekeepingModes.add(mode);
}
@Override
public void setBeekeepingMode(World world, String name) {
activeBeekeepingMode = getBeekeepingMode(name);
getBreedingTracker(world, null).setModeName(name);
}
@Override
public IBeekeepingMode getBeekeepingMode(String name) {
for (IBeekeepingMode mode : beekeepingModes) {
if (mode.getName().equals(name) || mode.getName().equals(name.toLowerCase(Locale.ENGLISH)))
return mode;
}
FMLCommonHandler.instance().getFMLLogger().debug("Failed to find a beekeeping mode called '%s', reverting to fallback.");
return beekeepingModes.get(0);
}
@Override
public IApiaristTracker getBreedingTracker(World world, GameProfile player) {
String filename = "ApiaristTracker." + (player == null ? "common" : player.getId());
ApiaristTracker tracker = (ApiaristTracker) world.loadItemData(ApiaristTracker.class, filename);
// Create a tracker if there is none yet.
if (tracker == null) {
tracker = new ApiaristTracker(filename, player);
world.setItemData(filename, tracker);
}
return tracker;
}
@Override
public IBeekeepingLogic createBeekeepingLogic(IBeeHousing housing) {
return new BeekeepingLogic(housing);
}
@Override
public IStructureLogic createAlvearyStructureLogic(IAlvearyComponent structure) {
return new StructureLogicAlveary(structure);
}
@Override
public IChromosomeType[] getKaryotype() {
return EnumBeeChromosome.values();
}
@Override
public IChromosomeType getKaryotypeKey() {
return EnumBeeChromosome.SPECIES;
}
}
+129
View File
@@ -0,0 +1,129 @@
/*******************************************************************************
* 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.genetics;
import java.util.ArrayList;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.common.BiomeDictionary;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeeMutation;
import forestry.api.apiculture.IBeeRoot;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IGenome;
import forestry.core.genetics.Mutation;
import forestry.plugins.PluginApiculture;
public class BeeMutation extends Mutation implements IBeeMutation {
private final IBeeRoot root;
boolean requiresDay = false;
boolean requiresNight = false;
private final ArrayList<BiomeDictionary.Type> restrictBiomeTypes = new ArrayList<BiomeDictionary.Type>();
private boolean strictBiomeCheck = false;
public BeeMutation(IAllele allele0, IAllele allele1, IAllele[] template, int chance) {
super(allele0, allele1, template, chance);
root = (IBeeRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootBees");
PluginApiculture.beeInterface.registerMutation(this);
}
@Override
public IBeeRoot getRoot() {
return root;
}
public BeeMutation enableStrictBiomeCheck() {
strictBiomeCheck = true;
return this;
}
public BeeMutation restrictBiomeType(BiomeDictionary.Type type) {
restrictBiomeTypes.add(type);
specialConditions.add(String.format("Is restricted to %s-like environments.", type.toString()));
return this;
}
public BeeMutation requireDay() {
requiresDay = true;
requiresNight = false;
specialConditions.add("Can only occur during the day.");
return this;
}
public BeeMutation requireNight() {
requiresDay = false;
requiresNight = true;
specialConditions.add("Can only occur during the night.");
return this;
}
@Override
public float getChance(IBeeHousing housing, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
World world = housing.getWorld();
if (requiresDay && !world.isDaytime())
return 0;
if (requiresNight && world.isDaytime())
return 0;
// Skip if we are restricted by biomes and this one does not match.
if (restrictBiomeTypes.size() > 0) {
boolean noneMatched = true;
BiomeGenBase biome = BiomeGenBase.getBiome(housing.getBiomeId());
if(strictBiomeCheck) {
BiomeDictionary.Type[] types = BiomeDictionary.getTypesForBiome(biome);
if(types.length == 1 && restrictBiomeTypes.contains(types[0]))
noneMatched = false;
} else {
for(BiomeDictionary.Type type : restrictBiomeTypes) {
if(BiomeDictionary.isBiomeOfType(biome, type)) {
noneMatched = false;
break;
}
}
}
if (noneMatched)
return 0;
}
BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(housing.getXCoord(), housing.getZCoord());
if (biome.temperature < minTemperature || biome.temperature > maxTemperature)
return 0;
if (biome.rainfall < minRainfall || biome.rainfall > maxRainfall)
return 0;
float processedChance = chance * housing.getMutationModifier((IBeeGenome) genome0, (IBeeGenome) genome1, 1f)
* PluginApiculture.beeInterface.getBeekeepingMode(world).getMutationModifier((IBeeGenome) genome0, (IBeeGenome) genome1, 1f);
if(processedChance <= 0)
return 0;
if (this.allele0.getUID().equals(allele0.getUID()) && this.allele1.getUID().equals(allele1.getUID()))
return processedChance;
if (this.allele1.getUID().equals(allele0.getUID()) && this.allele0.getUID().equals(allele1.getUID()))
return processedChance;
return 0;
}
}
@@ -0,0 +1,598 @@
/*******************************************************************************
* 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.genetics;
import forestry.api.apiculture.EnumBeeChromosome;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IMutation;
import forestry.core.genetics.Allele;
public class BeeTemplates {
// / MUTATIONS
public static IMutation commonA;
public static IMutation commonB;
public static IMutation commonC;
public static IMutation commonD;
public static IMutation commonE;
public static IMutation commonF;
public static IMutation commonG;
public static IMutation commonH;
public static IMutation commonI;
public static IMutation commonJ;
public static IMutation commonK;
public static IMutation commonL;
public static IMutation commonM;
public static IMutation commonN;
public static IMutation commonO;
public static IMutation cultivatedA;
public static IMutation cultivatedB;
public static IMutation cultivatedC;
public static IMutation cultivatedD;
public static IMutation cultivatedE;
public static IMutation cultivatedF;
public static IMutation nobleA;
public static IMutation majesticA;
public static IMutation imperialA;
public static IMutation diligentA;
public static IMutation unwearyA;
public static IMutation industriousA;
public static IMutation heroicA;
public static IMutation sinisterA;
public static IMutation sinisterB;
public static IMutation fiendishA;
public static IMutation fiendishB;
public static IMutation fiendishC;
public static IMutation demonicA;
// Austere branch
public static IMutation frugalA;
public static IMutation frugalB;
public static IMutation austereA;
// Tropical branch
public static IMutation exoticA;
public static IMutation edenicA;
// Wintry branch
public static IMutation icyA;
public static IMutation glacialA;
// Festive branch
public static IMutation leporineA;
public static IMutation merryA;
public static IMutation tipsyA;
public static IMutation trickyA;
// Agrarian branch
public static IMutation ruralA;
// Monastic branch
public static IMutation secludedA;
public static IMutation hermiticA;
// End branch
public static IMutation spectralA;
public static IMutation phantasmalA;
public static IMutation vindictiveA;
public static IMutation vengefulA;
public static IMutation vengefulB;
public static IMutation avengingA;
public static IAllele[] getDefaultTemplate() {
IAllele[] alleles = new IAllele[EnumBeeChromosome.values().length];
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesForest;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlowest;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShorter;
alleles[EnumBeeChromosome.FERTILITY.ordinal()] = Allele.fertilityNormal;
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceNone;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolFalse;
alleles[EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()] = Allele.toleranceNone;
alleles[EnumBeeChromosome.TOLERANT_FLYER.ordinal()] = Allele.boolFalse;
alleles[EnumBeeChromosome.CAVE_DWELLING.ordinal()] = Allele.boolFalse;
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersVanilla;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringSlowest;
alleles[EnumBeeChromosome.TERRITORY.ordinal()] = Allele.territoryDefault;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectNone;
return alleles;
}
// / COMMON BRANCH
public static IAllele[] getForestTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringSlower;
alleles[EnumBeeChromosome.FERTILITY.ordinal()] = Allele.fertilityHigh;
return alleles;
}
public static IAllele[] getForestRainResistTemplate() {
IAllele[] alleles = getForestTemplate();
alleles[EnumBeeChromosome.TOLERANT_FLYER.ordinal()] = Allele.boolTrue;
return alleles;
}
public static IAllele[] getMeadowsTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesMeadows;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringSlower;
return alleles;
}
public static IAllele[] getCommonTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesCommon;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
return alleles;
}
public static IAllele[] getCultivatedTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesCultivated;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedFast;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShortest;
return alleles;
}
// / NOBLE BRANCH
public static IAllele[] getNobleTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesNoble;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShort;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringSlow;
return alleles;
}
public static IAllele[] getMajesticTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesMajestic;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedNorm;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShortened;
alleles[EnumBeeChromosome.FERTILITY.ordinal()] = Allele.fertilityMaximum;
return alleles;
}
public static IAllele[] getImperialTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesImperial;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanNormal;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectBeatific;
return alleles;
}
// / INDUSTRIOUS BRANCH
public static IAllele[] getDiligentTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesDiligent;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShort;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringSlow;
return alleles;
}
public static IAllele[] getUnwearyTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesUnweary;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedNorm;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShortened;
return alleles;
}
public static IAllele[] getIndustriousTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesIndustrious;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanNormal;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringFast;
return alleles;
}
// / HEROIC BRANCH
public static IAllele[] getSteadfastTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesSteadfast;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanNormal;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.CAVE_DWELLING.ordinal()] = Allele.boolTrue;
return alleles;
}
public static IAllele[] getValiantTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesValiant;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlow;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLong;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.CAVE_DWELLING.ordinal()] = Allele.boolTrue;
return alleles;
}
public static IAllele[] getHeroicTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesHeroic;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlow;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLong;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.CAVE_DWELLING.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectHeroic;
return alleles;
}
// / INFERNAL BRANCH
public static IAllele[] getBranchInfernalTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceDown2;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersNether;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringAverage;
return alleles;
}
public static IAllele[] getSinisterTemplate() {
IAllele[] alleles = getBranchInfernalTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesSinister;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanNormal;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectAggressive;
return alleles;
}
public static IAllele[] getFiendishTemplate() {
IAllele[] alleles = getBranchInfernalTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesFiendish;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedNorm;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLong;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectAggressive;
return alleles;
}
public static IAllele[] getDemonicTemplate() {
IAllele[] alleles = getBranchInfernalTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesDemonic;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLonger;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectIgnition;
return alleles;
}
// / AUSTERE BRANCH
public static IAllele[] getAustereBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceBoth1;
alleles[EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()] = Allele.toleranceUp1;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersCacti;
return alleles;
}
public static IAllele[] getModestTemplate() {
IAllele[] alleles = getAustereBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesModest;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShort;
return alleles;
}
public static IAllele[] getFrugalTemplate() {
IAllele[] alleles = getAustereBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesFrugal;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedNorm;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLong;
return alleles;
}
public static IAllele[] getAustereTemplate() {
IAllele[] alleles = getAustereBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesAustere;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlowest;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLonger;
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceDown2;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectCreeper;
return alleles;
}
// / TROPICAL BRANCH
public static IAllele[] getTropicalBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceBoth1;
alleles[EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()] = Allele.toleranceDown1;
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersJungle;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectMiasmic;
return alleles;
}
public static IAllele[] getTropicalTemplate() {
IAllele[] alleles = getTropicalBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesTropical;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShort;
return alleles;
}
public static IAllele[] getExoticTemplate() {
IAllele[] alleles = getTropicalBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesExotic;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedNorm;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLong;
return alleles;
}
public static IAllele[] getEdenicTemplate() {
IAllele[] alleles = getTropicalBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesEdenic;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlowest;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLonger;
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceBoth2;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectExploration;
return alleles;
}
// / END BRANCH
public static IAllele[] getEndBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.FERTILITY.ordinal()] = Allele.fertilityLow;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLonger;
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceUp1;
alleles[EnumBeeChromosome.TERRITORY.ordinal()] = Allele.territoryLarge;
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersEnd;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectMisanthrope;
return alleles;
}
public static IAllele[] getEnderTemplate() {
IAllele[] alleles = getEndBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesEnded;
return alleles;
}
public static IAllele[] getSpectralTemplate() {
IAllele[] alleles = getEndBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesSpectral;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectReanimation;
return alleles;
}
public static IAllele[] getPhantasmalTemplate() {
IAllele[] alleles = getEndBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesPhantasmal;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlowest;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLongest;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectResurrection;
return alleles;
}
// / FROZEN BRANCH
public static IAllele[] getFrozenBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceUp1;
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersSnow;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectGlacial;
return alleles;
}
public static IAllele[] getWintryTemplate() {
IAllele[] alleles = getFrozenBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesWintry;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShort;
alleles[EnumBeeChromosome.FERTILITY.ordinal()] = Allele.fertilityMaximum;
return alleles;
}
public static IAllele[] getIcyTemplate() {
IAllele[] alleles = getFrozenBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesIcy;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlow;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShort;
return alleles;
}
public static IAllele[] getGlacialTemplate() {
IAllele[] alleles = getFrozenBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesGlacial;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShort;
return alleles;
}
// / VENGEFUL BRANCH
public static IAllele[] getVengefulBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.TERRITORY.ordinal()] = Allele.territoryLargest;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectRadioactive;
return alleles;
}
public static IAllele[] getVindictiveTemplate() {
IAllele[] alleles = getVengefulBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesVindictive;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanNormal;
return alleles;
}
public static IAllele[] getVengefulTemplate() {
IAllele[] alleles = getVengefulBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesVengeful;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedNorm;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLonger;
return alleles;
}
public static IAllele[] getAvengingTemplate() {
IAllele[] alleles = getVengefulBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesAvenging;
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlowest;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLongest;
return alleles;
}
// / REDDENED BRANCH
public static IAllele[] getReddenedBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlow;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanNormal;
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceBoth2;
alleles[EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()] = Allele.toleranceBoth1;
return alleles;
}
public static IAllele[] getDarkenedTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesDarkened;
return alleles;
}
public static IAllele[] getReddenedTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesReddened;
return alleles;
}
public static IAllele[] getOmegaTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesOmega;
return alleles;
}
// / FESTIVE BRANCH
public static IAllele[] getFestiveBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceBoth2;
alleles[EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()] = Allele.toleranceBoth1;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanNormal;
return alleles;
}
public static IAllele[] getLeporineTemplate() {
IAllele[] alleles = getFestiveBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesLeporine;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectFestiveEaster;
return alleles;
}
public static IAllele[] getMerryTemplate() {
IAllele[] alleles = getFestiveBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesMerry;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectSnowing;
return alleles;
}
public static IAllele[] getTipsyTemplate() {
IAllele[] alleles = getFestiveBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesTipsy;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectDrunkard;
return alleles;
}
public static IAllele[] getTrickyTemplate() {
IAllele[] alleles = getFestiveBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesTricky;
alleles[EnumBeeChromosome.NOCTURNAL.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.TOLERANT_FLYER.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersGourd;
return alleles;
}
// / AGRARIAN BRANCH
public static IAllele[] getAgrarianBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanShorter;
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersWheat;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringFaster;
return alleles;
}
public static IAllele[] getRuralTemplate() {
IAllele[] alleles = getAgrarianBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesRural;
return alleles;
}
// / BOGGY BRANCH
public static IAllele[] getBoggyBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersMushrooms;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringSlower;
alleles[EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()] = Allele.toleranceBoth1;
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceBoth1;
return alleles;
}
public static IAllele[] getMarshyTemplate() {
IAllele[] alleles = getBoggyBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesMarshy;
return alleles;
}
/* MONASTIC BRANCH */
public static IAllele[] getMonasticBranchTemplate() {
IAllele[] alleles = getDefaultTemplate();
alleles[EnumBeeChromosome.SPEED.ordinal()] = Allele.speedSlower;
alleles[EnumBeeChromosome.LIFESPAN.ordinal()] = Allele.lifespanLong;
alleles[EnumBeeChromosome.FERTILITY.ordinal()] = Allele.fertilityLow;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringFaster;
alleles[EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()] = Allele.toleranceBoth1;
alleles[EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()] = Allele.toleranceBoth1;
alleles[EnumBeeChromosome.CAVE_DWELLING.ordinal()] = Allele.boolTrue;
alleles[EnumBeeChromosome.FLOWER_PROVIDER.ordinal()] = Allele.flowersWheat;
return alleles;
}
public static IAllele[] getMonasticTemplate() {
IAllele[] alleles = getMonasticBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesMonastic;
return alleles;
}
public static IAllele[] getSecludedTemplate() {
IAllele[] alleles = getMonasticBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesSecluded;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringFastest;
return alleles;
}
public static IAllele[] getHermiticTemplate() {
IAllele[] alleles = getMonasticBranchTemplate();
alleles[EnumBeeChromosome.SPECIES.ordinal()] = Allele.speciesHermitic;
alleles[EnumBeeChromosome.FLOWERING.ordinal()] = Allele.floweringFastest;
alleles[EnumBeeChromosome.EFFECT.ordinal()] = Allele.effectRepulsion;
return alleles;
}
}
@@ -0,0 +1,177 @@
/*******************************************************************************
* 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.genetics;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Random;
import net.minecraft.world.World;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IBeekeepingMode;
public class BeekeepingMode implements IBeekeepingMode {
public static IBeekeepingMode easy = new BeekeepingMode("EASY", 2.0f, 1.0f, 1.0f, false, false);
public static IBeekeepingMode normal = new BeekeepingMode("NORMAL", 1.0f, 1.0f, 1.0f, false, true);
public static IBeekeepingMode hard = new BeekeepingMode("HARD", 0.75f, 1.5f, 1.0f, false, true);
public static IBeekeepingMode hardcore = new BeekeepingMode("HARDCORE", 0.5f, 5.0f, 0.8f, true, true);
public static IBeekeepingMode insane = new BeekeepingMode("INSANE", 0.2f, 10.0f, 0.6f, true, true);
final Random rand;
final String name;
final float mutationModifier;
final float lifespanModifier;
final float speedModifier;
final boolean reducesFertility;
final boolean canFatigue;
public BeekeepingMode(String name, float mutationModifier, float lifespanModifier, float speedModifier, boolean reducesFertility, boolean canFatigue) {
this.rand = new Random();
this.name = name;
this.mutationModifier = mutationModifier;
this.lifespanModifier = lifespanModifier;
this.speedModifier = speedModifier;
this.reducesFertility = reducesFertility;
this.canFatigue = canFatigue;
}
@Override
public String getName() {
return this.name;
}
@Override
public ArrayList<String> getDescription() {
ArrayList<String> ret = new ArrayList<String>();
ret.add("beemode." + name.toLowerCase(Locale.ENGLISH) + ".desc");
return ret;
}
@Override
public float getWearModifier() {
return 1.0f;
}
@Override
public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
return this.mutationModifier;
}
@Override
public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
return this.lifespanModifier;
}
@Override
public float getProductionModifier(IBeeGenome genome, float currentModifier) {
return this.speedModifier;
}
@Override
public float getTerritoryModifier(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public float getFloweringModifier(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public float getGeneticDecay(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public int getFinalFertility(IBee queen, World world, int x, int y, int z) {
int toCreate = queen.getGenome().getFertility();
if (reducesFertility)
toCreate = new Random().nextInt(toCreate);
return toCreate;
}
@Override
public boolean isFatigued(IBee queen, IBeeHousing housing) {
if (!canFatigue)
return false;
if (queen.isNatural())
return false;
if (queen.getGeneration() > 96 + rand.nextInt(6) + rand.nextInt(6) &&
rand.nextFloat() < 0.02f * housing.getGeneticDecay(queen.getGenome(), 1f))
return true;
return false;
}
@Override
public boolean isOverworked(IBee queen, IBeeHousing housing) {
float productionModifier = housing.getProductionModifier(queen.getGenome(), 1f);
if(productionModifier > 16) {
if(housing.getWorld().rand.nextFloat()*100 < 0.01 * ((productionModifier*productionModifier) - 100))
return true;
}
return false;
}
@Override
public boolean isDegenerating(IBee queen, IBee offspring, IBeeHousing housing) {
float mutationModifier = housing.getMutationModifier(queen.getGenome(), queen.getMate(), 1.0f);
if(mutationModifier > 10) {
if(housing.getWorld().rand.nextFloat()*100 < 0.4 * ((mutationModifier*mutationModifier) - 100))
return true;
}
return false;
}
@Override
public boolean isNaturalOffspring(IBee queen) {
if (!queen.isNatural())
return false;
return true;
}
@Override
public boolean mayMultiplyPrincess(IBee queen) {
return true;
}
@Override
public boolean isSealed() {
return false;
}
@Override
public boolean isSelfLighted() {
return false;
}
@Override
public boolean isSunlightSimulated() {
return false;
}
@Override
public boolean isHellish() {
return false;
}
}
+21
View File
@@ -0,0 +1,21 @@
/*******************************************************************************
* 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.genetics;
import forestry.core.genetics.Branch;
public class BranchBees extends Branch {
public BranchBees(String uid, String scientific) {
super("bees." + uid, scientific);
}
}
+78
View File
@@ -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.genetics;
import java.util.ArrayList;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IHiveDrop;
import forestry.api.genetics.IAllele;
import forestry.plugins.PluginApiculture;
public class HiveDrop implements IHiveDrop {
private IAllele[] template;
private ArrayList<ItemStack> additional = new ArrayList<ItemStack>();
private int chance;
private float ignobleShare = 0.0f;
public HiveDrop(IAllele[] template, ItemStack[] bonus, int chance) {
this.template = template;
this.chance = chance;
for (ItemStack stack : bonus)
this.additional.add(stack);
}
public HiveDrop setIgnobleShare(float share) {
this.ignobleShare = share;
return this;
}
private IBee createBee(World world) {
IBee bee = PluginApiculture.beeInterface.getBee(world, PluginApiculture.beeInterface.templateAsGenome(template));
if(world.rand.nextFloat() < ignobleShare)
bee.setIsNatural(false);
return bee;
}
@Override
public ItemStack getPrincess(World world, int x, int y, int z, int fortune) {
return PluginApiculture.beeInterface.getMemberStack(createBee(world), EnumBeeType.PRINCESS.ordinal());
}
@Override
public ArrayList<ItemStack> getDrones(World world, int x, int y, int z, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
ret.add(PluginApiculture.beeInterface.getMemberStack(createBee(world),
EnumBeeType.DRONE.ordinal()));
return ret;
}
@Override
public ArrayList<ItemStack> getAdditional(World world, int x, int y, int z, int fortune) {
ArrayList<ItemStack> ret = new ArrayList<ItemStack>();
for (ItemStack stack : additional)
ret.add(stack.copy());
return ret;
}
@Override
public int getChance(World world, int x, int y, int z) {
return chance;
}
}
@@ -0,0 +1,19 @@
/*******************************************************************************
* 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.genetics;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
public interface IJubilanceProvider {
boolean isJubilant(IAlleleBeeSpecies species, IBeeGenome genome, IBeeHousing housing);
}
@@ -0,0 +1,47 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.biome.BiomeGenBase;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.core.EnumHumidity;
import forestry.api.core.EnumTemperature;
import forestry.core.utils.Vect;
public class JubilanceDefault implements IJubilanceProvider {
@Override
public boolean isJubilant(IAlleleBeeSpecies species, IBeeGenome genome, IBeeHousing housing) {
BiomeGenBase biome = BiomeGenBase.getBiome(housing.getBiomeId());
if (EnumTemperature.getFromValue(biome.temperature) != species.getTemperature() ||
EnumHumidity.getFromValue(biome.rainfall) != species.getHumidity())
return false;
return true;
}
protected AxisAlignedBB getBounding(IBeeGenome genome, IBeeHousing housing, float modifier) {
int[] areaAr = genome.getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]).multiply(modifier);
Vect offset = new Vect(-Math.round(area.x / 2), -Math.round(area.y / 2), -Math.round(area.z / 2));
Vect min = new Vect(housing.getXCoord() + offset.x, housing.getYCoord() + offset.y, housing.getZCoord() + offset.z);
Vect max = new Vect(housing.getXCoord() + offset.x + area.x, housing.getYCoord() + offset.y + area.y, housing.getZCoord() + offset.z + area.z);
return AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
}
}
@@ -0,0 +1,24 @@
/*******************************************************************************
* 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.genetics;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
public class JubilanceNone implements IJubilanceProvider {
@Override
public boolean isJubilant(IAlleleBeeSpecies species, IBeeGenome genome, IBeeHousing housing) {
return false;
}
}
@@ -0,0 +1,39 @@
/*******************************************************************************
* 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.genetics;
import java.util.List;
import net.minecraft.entity.EntityLiving;
import net.minecraft.util.AxisAlignedBB;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
/**
* Hermits will not produce if there are any other living creatures nearby.
*/
public class JubilanceProviderHermit extends JubilanceDefault {
@Override
public boolean isJubilant(IAlleleBeeSpecies species, IBeeGenome genome, IBeeHousing housing) {
AxisAlignedBB bounding = this.getBounding(genome, housing, 1.0f);
@SuppressWarnings("rawtypes")
List list = housing.getWorld().getEntitiesWithinAABB(EntityLiving.class, bounding);
if (list.size() > 0)
return false;
return true;
}
}
@@ -0,0 +1,43 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.core.utils.StackUtils;
public class JubilanceReqRes implements IJubilanceProvider {
private final ItemStack blockRequired;
public JubilanceReqRes(ItemStack blockRequired) {
this.blockRequired = blockRequired;
}
@Override
public boolean isJubilant(IAlleleBeeSpecies species, IBeeGenome genome, IBeeHousing housing) {
if (blockRequired == null)
return true;
Block block = housing.getWorld().getBlock(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord());
int meta = housing.getWorld().getBlockMetadata(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord());
if (StackUtils.equals(block, blockRequired) && meta == blockRequired.getItemDamage())
return true;
else
return false;
}
}
@@ -0,0 +1,96 @@
/*******************************************************************************
* 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.genetics;
import java.lang.reflect.Field;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IGenome;
import forestry.core.proxy.Proxies;
import forestry.core.utils.Vect;
public class MutationEMC extends MutationReqRes {
int emcRequired = 0;
Class<?> condenserClass;
Field emcField;
public MutationEMC(IAllele allele0, IAllele allele1, IAllele[] template, int chance, ItemStack blockRequired, Class<?> condenserClass, Field emcField,
int emcRequired) {
super(allele0, allele1, template, chance, blockRequired);
this.condenserClass = condenserClass;
this.emcField = emcField;
this.emcRequired = emcRequired;
}
@Override
public float getChance(IBeeHousing housing, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
float chance = super.getChance(housing, allele0, allele1, genome0, genome1);
// If we don't have any chance, return at once.
if (chance <= 0)
return 0;
if (emcRequired <= 0)
return chance;
World world = housing.getWorld();
Vect[] possibleTargets = new Vect[] { new Vect(housing.getXCoord() + 1, housing.getYCoord(), housing.getZCoord()),
new Vect(housing.getXCoord() - 1, housing.getYCoord(), housing.getZCoord()),
new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord() + 1),
new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord() - 1) };
for (Vect target : possibleTargets) {
if (!world.blockExists(target.x, target.y, target.z))
continue;
TileEntity entity = world.getTileEntity(target.x, target.y, target.z);
if (entity == null)
continue;
if (!condenserClass.isInstance(entity)) {
Proxies.log.warning("Did not find a relay at " + target.toString());
continue;
}
int emc = 0;
try {
emc = emcField.getInt(entity);
} catch (Exception ex) {
Proxies.log.warning("Failed to fetch EMC information.");
}
if (emc < emcRequired * 80)
continue;
boolean removedEMC = false;
try {
emcField.set(entity, emc - (emcRequired * 80));
removedEMC = true;
} catch (Exception ex) {
Proxies.log.warning("Failed to set EMC information.");
}
if (removedEMC)
return chance;
}
return 0;
}
}
@@ -0,0 +1,50 @@
/*******************************************************************************
* 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.genetics;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IGenome;
import forestry.core.utils.StackUtils;
public class MutationReqRes extends BeeMutation {
private final ItemStack blockRequired;
public MutationReqRes(IAllele allele0, IAllele allele1, IAllele[] template, int chance, ItemStack blockRequired) {
super(allele0, allele1, template, chance);
this.blockRequired = blockRequired;
}
@Override
public float getChance(IBeeHousing housing, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
float chance = super.getChance(housing, allele0, allele1, genome0, genome1);
// If we have no chance anyway, we don't need to check.
if (chance <= 0)
return 0;
World world = housing.getWorld();
if (blockRequired == null)
return chance;
Block block = world.getBlock(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord());
int meta = world.getBlockMetadata(housing.getXCoord(), housing.getYCoord() - 1, housing.getZCoord());
if (StackUtils.equals(block, blockRequired) && meta == blockRequired.getItemDamage())
return chance;
else
return 0;
}
}
@@ -0,0 +1,140 @@
/*******************************************************************************
* 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.genetics;
import java.util.Calendar;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IGenome;
public class MutationTimeLimited extends BeeMutation {
/**
* Fed up with Date and Calendar and their shinenigans
*/
public static class DayMonth {
public int day;
public int month;
public DayMonth() {
this.day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
this.month = Calendar.getInstance().get(Calendar.MONTH) + 1;
}
public DayMonth(int day, int month) {
this.day = day;
this.month = month;
}
public boolean between(DayMonth start, DayMonth end) {
if (equals(start) || equals(end))
return true;
if (start.month > end.month)
return after(start) || before(end);
return after(start) && before(end);
}
public boolean before(DayMonth other) {
if (other.month > this.month)
return true;
if (other.month < this.month)
return false;
return this.day < other.day;
}
public boolean after(DayMonth other) {
if (other.month < this.month)
return true;
if (other.month > this.month)
return false;
return this.day > other.day;
}
@Override
public int hashCode() {
int hash = 7;
hash = 89 * hash + this.day;
hash = 89 * hash + this.month;
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final DayMonth other = (DayMonth) obj;
if (this.day != other.day)
return false;
if (this.month != other.month)
return false;
return true;
}
@Override
public String toString() {
return day + "." + month;
}
}
DayMonth start;
DayMonth end;
public MutationTimeLimited(IAllele allele0, IAllele allele1, IAllele[] template, int chance, DayMonth start) {
this(allele0, allele1, template, chance, start, null);
}
public MutationTimeLimited(IAllele allele0, IAllele allele1, IAllele[] template, int chance, DayMonth start, DayMonth end) {
super(allele0, allele1, template, chance);
this.start = start;
this.end = end;
}
@Override
public float getChance(IBeeHousing housing, IAllele allele0, IAllele allele1, IGenome genome0, IGenome genome1) {
float chance = super.getChance(housing, allele0, allele1, genome0, genome1);
if (chance == 0)
return 0;
if (start == null && end == null)
return chance;
DayMonth now = new DayMonth();
// If we are equal to start day, return chance.
if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == start.day && Calendar.getInstance().get(Calendar.MONTH) + 1 == start.month)
return chance;
// Still here but not time span? No mutation!
if (end == null)
return 0;
// Equal to end date, return chance.
if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) == end.day && Calendar.getInstance().get(Calendar.MONTH) + 1 == end.month)
return chance;
// Still a chance we are in between
if (now.between(start, end))
return chance;
// Now we finally failed.
return 0;
}
}
@@ -0,0 +1,69 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import forestry.apiculture.gadgets.TileAlvearyPlain;
import forestry.core.config.ForestryItem;
import forestry.core.gui.ContainerForestry;
import forestry.core.gui.slots.SlotClosed;
import forestry.core.gui.slots.SlotCustom;
public class ContainerAlveary extends ContainerForestry {
private TileAlvearyPlain tile;
public ContainerAlveary(InventoryPlayer player, TileAlvearyPlain tile) {
super(tile);
this.tile = tile;
tile.sendNetworkUpdate();
// Queen/Princess
this.addSlot(new SlotCustom(tile, TileAlvearyPlain.SLOT_QUEEN, 29, 39, new Object[] { ForestryItem.beePrincessGE, ForestryItem.beeQueenGE }));
// Drone
this.addSlot(new SlotCustom(tile, TileAlvearyPlain.SLOT_DRONE, 29, 65, new Object[] { ForestryItem.beeDroneGE }));
// Product Inventory
this.addSlot(new SlotClosed(tile, 2, 116, 52));
this.addSlot(new SlotClosed(tile, 3, 137, 39));
this.addSlot(new SlotClosed(tile, 4, 137, 65));
this.addSlot(new SlotClosed(tile, 5, 116, 78));
this.addSlot(new SlotClosed(tile, 6, 95, 65));
this.addSlot(new SlotClosed(tile, 7, 95, 39));
this.addSlot(new SlotClosed(tile, 8, 116, 26));
// Player inventory
for (int i = 0; i < 3; i++)
for (int j = 0; j < 9; j++)
addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 108 + i * 18));
// Player hotbar
for (int i = 0; i < 9; i++)
addSlot(new Slot(player, i, 8 + i * 18, 166));
}
@Override
public void updateProgressBar(int i, int j) {
tile.getGUINetworkData(i, j);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < crafters.size(); i++)
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
}
}
@@ -0,0 +1,53 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import forestry.apiculture.gadgets.TileAlvearyHygroregulator;
import forestry.core.gui.ContainerLiquidTanks;
import forestry.core.gui.slots.SlotLiquidContainer;
public class ContainerAlvearyHygroregulator extends ContainerLiquidTanks {
TileAlvearyHygroregulator tile;
public ContainerAlvearyHygroregulator(IInventory inventory, TileAlvearyHygroregulator tile) {
super(inventory, tile);
this.tile = tile;
this.addSlot(new SlotLiquidContainer(tile, 0, 56, 38));
for (int i = 0; i < 3; ++i)
for (int var4 = 0; var4 < 9; ++var4)
this.addSlot(new Slot(inventory, var4 + i * 9 + 9, 8 + var4 * 18, 84 + i * 18));
for (int i = 0; i < 9; ++i)
this.addSlot(new Slot(inventory, i, 8 + i * 18, 142));
}
@Override
public void updateProgressBar(int i, int j) {
tile.getGUINetworkData(i, j);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < crafters.size(); i++)
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
}
}
@@ -0,0 +1,57 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import forestry.apiculture.gadgets.TileAlvearySieve;
import forestry.core.config.ForestryItem;
import forestry.core.gui.ContainerForestry;
import forestry.core.gui.slots.SlotCustom;
public class ContainerAlvearySieve extends ContainerForestry {
TileAlvearySieve tile;
public ContainerAlvearySieve(InventoryPlayer player, TileAlvearySieve tile) {
super(tile.getInternalInventory());
this.tile = tile;
IInventory inventory = tile.getInternalInventory();
addSlot(new SlotCustom(inventory, 0, 94, 52, new Object[0]).setCrafter(tile));
addSlot(new SlotCustom(inventory, 1, 115, 39, new Object[0]).setCrafter(tile));
addSlot(new SlotCustom(inventory, 2, 73, 39, new Object[0]).setCrafter(tile));
addSlot(new SlotCustom(inventory, 3, 94, 26, new Object[0]).setCrafter(tile));
addSlot(new SlotCustom(inventory, TileAlvearySieve.SLOT_SIEVE, 43, 39, ForestryItem.craftingMaterial.getItemStack(1, 3)).setCrafter(tile));
// Player inventory
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 87 + i * 18));
}
}
// Player hotbar
for (int i = 0; i < 9; i++) {
addSlot(new Slot(player, i, 8 + i * 18, 145));
}
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return tile.isUseableByPlayer(entityplayer);
}
}
@@ -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.apiculture.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import forestry.api.apiculture.BeeManager;
import forestry.apiculture.gadgets.TileAlvearySwarmer;
import forestry.core.gui.ContainerForestry;
import forestry.core.gui.slots.SlotCustom;
public class ContainerAlvearySwarmer extends ContainerForestry {
public ContainerAlvearySwarmer(InventoryPlayer player, TileAlvearySwarmer tile) {
super(tile);
this.addSlot(new SlotCustom(tile, 0, 79, 52, getInducerItems()));
this.addSlot(new SlotCustom(tile, 1, 100, 39, getInducerItems()));
this.addSlot(new SlotCustom(tile, 2, 58, 39, getInducerItems()));
this.addSlot(new SlotCustom(tile, 3, 79, 26, getInducerItems()));
// Player inventory
for (int i = 0; i < 3; i++)
for (int j = 0; j < 9; j++)
addSlot(new Slot(player, j + i * 9 + 9, 8 + j * 18, 87 + i * 18));
// Player hotbar
for (int i = 0; i < 9; i++)
addSlot(new Slot(player, i, 8 + i * 18, 145));
}
private Object[] getInducerItems() {
return BeeManager.inducers.keySet().toArray(new Object[0]);
}
}
+89
View File
@@ -0,0 +1,89 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import forestry.api.apiculture.IHiveFrame;
import forestry.apiculture.gadgets.TileBeehouse;
import forestry.core.config.ForestryItem;
import forestry.core.gui.ContainerForestry;
import forestry.core.gui.slots.SlotClosed;
import forestry.core.gui.slots.SlotCustom;
import forestry.core.utils.Utils;
public class ContainerApiary extends ContainerForestry {
private final TileBeehouse tile;
public ContainerApiary(InventoryPlayer player, TileBeehouse tile, boolean hasFrames) {
super(tile.getInternalInventory());
this.tile = tile;
tile.sendNetworkUpdate();
IInventory inventory = tile.getInternalInventory();
// Queen/Princess
this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_QUEEN, 29, 39, ForestryItem.beePrincessGE, ForestryItem.beeQueenGE));
// Drone
this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_DRONE, 29, 65, ForestryItem.beeDroneGE));
// Frames
if (hasFrames) {
this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_FRAMES_1, 66, 23, IHiveFrame.class));
this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_FRAMES_1 + 1, 66, 52, IHiveFrame.class));
this.addSlot(new SlotCustom(inventory, TileBeehouse.SLOT_FRAMES_1 + 2, 66, 81, IHiveFrame.class));
}
// Product Inventory
this.addSlot(new SlotClosed(inventory, 2, 116, 52));
this.addSlot(new SlotClosed(inventory, 3, 137, 39));
this.addSlot(new SlotClosed(inventory, 4, 137, 65));
this.addSlot(new SlotClosed(inventory, 5, 116, 78));
this.addSlot(new SlotClosed(inventory, 6, 95, 65));
this.addSlot(new SlotClosed(inventory, 7, 95, 39));
this.addSlot(new SlotClosed(inventory, 8, 116, 26));
// Player inventory
for (int i1 = 0; i1 < 3; i1++) {
for (int l1 = 0; l1 < 9; l1++) {
addSlot(new Slot(player, l1 + i1 * 9 + 9, 8 + l1 * 18, 108 + i1 * 18));
}
}
// Player hotbar
for (int j1 = 0; j1 < 9; j1++) {
addSlot(new Slot(player, j1, 8 + j1 * 18, 166));
}
}
@Override
public void updateProgressBar(int i, int j) {
tile.getGUINetworkData(i, j);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < crafters.size(); i++) {
tile.sendGUINetworkData(this, (ICrafting) crafters.get(i));
}
}
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return Utils.isUseableByPlayer(entityplayer, tile, tile.getWorld(), tile.xCoord, tile.yCoord, tile.zCoord);
}
}
@@ -0,0 +1,83 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import forestry.apiculture.items.ItemBeeGE;
import forestry.apiculture.items.ItemBeealyzer.BeealyzerInventory;
import forestry.core.config.ForestryItem;
import forestry.core.gui.ContainerItemInventory;
import forestry.core.gui.slots.SlotCustom;
import forestry.core.proxy.Proxies;
public class ContainerBeealyzer extends ContainerItemInventory {
BeealyzerInventory inventory;
public ContainerBeealyzer(InventoryPlayer inventoryplayer, BeealyzerInventory inventory) {
super(inventory, inventoryplayer.player);
this.inventory = inventory;
// Energy
this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ENERGY, 172, 8, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop }));
// Bee to analyze
this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_SPECIMEN, 172, 26, new Object[] { ItemBeeGE.class }));
// Analyzed bee
this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_1, 172, 57, new Object[] { ItemBeeGE.class }));
this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_2, 172, 75, new Object[] { ItemBeeGE.class }));
this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_3, 172, 93, new Object[] { ItemBeeGE.class }));
this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_4, 172, 111, new Object[] { ItemBeeGE.class }));
this.addSlot(new SlotCustom(inventory, BeealyzerInventory.SLOT_ANALYZE_5, 172, 129, new Object[] { ItemBeeGE.class }));
// Player inventory
for (int i1 = 0; i1 < 3; i1++)
for (int l1 = 0; l1 < 9; l1++)
addSecuredSlot(inventoryplayer, l1 + i1 * 9 + 9, 18 + l1 * 18, 156 + i1 * 18);
// Player hotbar
for (int j1 = 0; j1 < 9; j1++)
addSecuredSlot(inventoryplayer, j1, 18 + j1 * 18, 214);
}
@Override
public void onContainerClosed(EntityPlayer entityplayer) {
if (!Proxies.common.isSimulating(entityplayer.worldObj))
return;
// Last slot is the energy slot, so we don't save that one.
for (int i = 0; i < inventory.getSizeInventory(); i++) {
if (i == BeealyzerInventory.SLOT_ENERGY)
continue;
ItemStack stack = inventory.getStackInSlot(i);
if (stack == null)
continue;
Proxies.common.dropItemPlayer(entityplayer, stack);
inventory.setInventorySlotContents(i, null);
}
inventory.onGuiSaved(entityplayer);
}
@Override
protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) {
return true;
}
}
@@ -0,0 +1,77 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import forestry.apiculture.items.ItemBeeGE;
import forestry.apiculture.items.ItemBiomefinder;
import forestry.apiculture.items.ItemBiomefinder.BiomefinderInventory;
import forestry.core.config.ForestryItem;
import forestry.core.gui.ContainerItemInventory;
import forestry.core.gui.slots.SlotCustom;
import forestry.core.proxy.Proxies;
public class ContainerHabitatLocator extends ContainerItemInventory {
public BiomefinderInventory inventory;
public ContainerHabitatLocator(InventoryPlayer inventoryplayer, BiomefinderInventory inventory) {
super(inventory, inventoryplayer.player);
this.inventory = inventory;
// Energy
this.addSlot(new SlotCustom(inventory, 2, 152, 8, new Object[] { ForestryItem.honeydew, ForestryItem.honeyDrop }));
// Bee to analyze
this.addSlot(new SlotCustom(inventory, 0, 152, 32, new Object[] { ItemBeeGE.class }));
// Analyzed bee
this.addSlot(new SlotCustom(inventory, 1, 152, 75, new Object[] { ItemBeeGE.class }));
// Player inventory
for (int i1 = 0; i1 < 3; i1++)
for (int l1 = 0; l1 < 9; l1++)
addSecuredSlot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 102 + i1 * 18);
// Player hotbar
for (int j1 = 0; j1 < 9; j1++)
addSecuredSlot(inventoryplayer, j1, 8 + j1 * 18, 160);
}
@Override
public void onContainerClosed(EntityPlayer entityplayer) {
if (!Proxies.common.isSimulating(entityplayer.worldObj))
return;
((ItemBiomefinder) ForestryItem.biomeFinder.item()).startBiomeSearch(entityplayer.worldObj, entityplayer, inventory.biomesToSearch);
for (int i = 0; i < inventory.getSizeInventory() - 1; i++) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack == null)
continue;
Proxies.common.dropItemPlayer(entityplayer, stack);
inventory.setInventorySlotContents(i, null);
}
inventory.onGuiSaved(entityplayer);
}
@Override
protected boolean isAcceptedItem(EntityPlayer player, ItemStack stack) {
return false;
}
}
@@ -0,0 +1,124 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import forestry.apiculture.items.ItemBeeGE;
import forestry.apiculture.items.ItemImprinter.ImprinterInventory;
import forestry.core.gui.ContainerForestry;
import forestry.core.gui.IGuiSelectable;
import forestry.core.gui.slots.SlotCustom;
import forestry.core.network.PacketIds;
import forestry.core.network.PacketPayload;
import forestry.core.network.PacketUpdate;
import forestry.core.proxy.Proxies;
public class ContainerImprinter extends ContainerForestry implements IGuiSelectable {
public ImprinterInventory inventory;
private boolean isNetSynched = false;
public ContainerImprinter(InventoryPlayer inventoryplayer, ImprinterInventory inventory) {
super(inventory);
this.inventory = inventory;
// Input
this.addSlot(new SlotCustom(inventory, 0, 152, 12, new Object[] { ItemBeeGE.class }));
// Output
this.addSlot(new SlotCustom(inventory, 1, 152, 72, new Object[] { ItemBeeGE.class }));
// Player inventory
for (int i1 = 0; i1 < 3; i1++)
for (int l1 = 0; l1 < 9; l1++)
addSlot(new Slot(inventoryplayer, l1 + i1 * 9 + 9, 8 + l1 * 18, 103 + i1 * 18));
// Player hotbar
for (int j1 = 0; j1 < 9; j1++)
addSlot(new Slot(inventoryplayer, j1, 8 + j1 * 18, 161));
}
@Override
public void onContainerClosed(EntityPlayer entityplayer) {
if (!Proxies.common.isSimulating(entityplayer.worldObj))
return;
// Drop everything still in there.
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack stack = inventory.getStackInSlot(i);
if (stack == null)
continue;
Proxies.common.dropItemPlayer(entityplayer, stack);
inventory.setInventorySlotContents(i, null);
}
}
public void advanceSelection(int index, World world) {
PacketPayload payload = new PacketPayload(2, 0, 0);
payload.intPayload[0] = index;
payload.intPayload[1] = 0;
sendSelectionChange(payload);
}
public void regressSelection(int index, World world) {
PacketPayload payload = new PacketPayload(2, 0, 0);
payload.intPayload[0] = index;
payload.intPayload[1] = 1;
sendSelectionChange(payload);
}
private void sendSelectionChange(PacketPayload payload) {
PacketUpdate packet = new PacketUpdate(PacketIds.GUI_SELECTION_CHANGE, payload);
Proxies.net.sendToServer(packet);
isNetSynched = false;
}
@Override
public void setSelection(PacketUpdate packet) {
inventory.setPrimaryIndex(packet.payload.intPayload[0]);
inventory.setSecondaryIndex(packet.payload.intPayload[1]);
}
public void updateContainer(World world) {
if (!isNetSynched && !Proxies.common.isSimulating(world)) {
isNetSynched = true;
Proxies.net.sendToServer(new PacketUpdate(PacketIds.IMPRINT_SELECTION_GET));
}
}
@Override
public void handleSelectionChange(EntityPlayer player, PacketUpdate packet) {
if (packet.payload.intPayload[1] == 0) {
if (packet.payload.intPayload[0] == 0)
inventory.advancePrimary();
else
inventory.advanceSecondary();
} else if (packet.payload.intPayload[0] == 0)
inventory.regressPrimary();
else
inventory.regressSecondary();
}
public void sendSelection(EntityPlayer player) {
PacketPayload payload = new PacketPayload(2, 0, 0);
payload.intPayload[0] = inventory.getPrimaryIndex();
payload.intPayload[1] = inventory.getSecondaryIndex();
Proxies.net.sendToPlayer(new PacketUpdate(PacketIds.GUI_SELECTION, payload), player);
}
}
+68
View File
@@ -0,0 +1,68 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.apiculture.gadgets.TileAlvearyPlain;
import forestry.core.config.Defaults;
import forestry.core.gui.GuiForestry;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.StringUtil;
import forestry.core.utils.Utils;
public class GuiAlveary extends GuiForestry<TileAlvearyPlain> {
public GuiAlveary(InventoryPlayer inventory, TileAlvearyPlain tile) {
super(Defaults.TEXTURE_PATH_GUI + "/alveary.png", new ContainerAlveary(inventory, tile), tile);
ySize = 190;
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
String title = StringUtil.localize("tile." + tile.getInventoryName());
this.fontRendererObj.drawString(title, getCenteredOffset(title), 6, fontColor.get("gui.title"));
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
TileAlvearyPlain machine = tile;
drawHealthMeter(guiLeft + 20, guiTop + 37, machine.getHealthScaled(46), Utils.rateTankLevel(machine.getHealthScaled(100)));
}
private void drawHealthMeter(int x, int y, int height, EnumTankLevel rated) {
int i = 176;
int k = 0;
switch (rated) {
case EMPTY:
break;
case LOW:
i += 4;
break;
case MEDIUM:
i += 8;
break;
case HIGH:
i += 12;
break;
case MAXIMUM:
i += 16;
break;
}
this.drawTexturedModalRect(x, y + 46 - height, i, k + 46 - height, 4, height);
}
}
@@ -0,0 +1,36 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.apiculture.gadgets.TileAlvearyHygroregulator;
import forestry.core.config.Defaults;
import forestry.core.gui.GuiForestry;
import forestry.core.gui.widgets.TankWidget;
import forestry.core.utils.StringUtil;
public class GuiAlvearyHygroregulator extends GuiForestry<TileAlvearyHygroregulator> {
public GuiAlvearyHygroregulator(InventoryPlayer inventory, TileAlvearyHygroregulator tile) {
super(Defaults.TEXTURE_PATH_GUI + "/hygroregulator.png", new ContainerAlvearyHygroregulator(inventory, tile));
widgetManager.add(new TankWidget(this.widgetManager, 104, 17, 0));
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
String name = StringUtil.localize("tile.alveary.5");
this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title"));
}
}
+26
View File
@@ -0,0 +1,26 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.apiculture.gadgets.TileAlvearySieve;
import forestry.core.config.Defaults;
import forestry.core.gui.GuiForestry;
public class GuiAlvearySieve extends GuiForestry<TileAlvearySieve> {
public GuiAlvearySieve(InventoryPlayer inventory, TileAlvearySieve tile) {
super(Defaults.TEXTURE_PATH_GUI + "/sieve.png", new ContainerAlvearySieve(inventory, tile));
}
}
@@ -0,0 +1,25 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.apiculture.gadgets.TileAlvearySwarmer;
import forestry.core.config.Defaults;
import forestry.core.gui.GuiForestry;
public class GuiAlvearySwarmer extends GuiForestry<TileAlvearySwarmer> {
public GuiAlvearySwarmer(InventoryPlayer inventory, TileAlvearySwarmer tile) {
super(Defaults.TEXTURE_PATH_GUI + "/swarmer.png", new ContainerAlvearySwarmer(inventory, tile));
}
}
+75
View File
@@ -0,0 +1,75 @@
/*******************************************************************************
* 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.gui;
import net.minecraft.entity.player.InventoryPlayer;
import forestry.apiculture.gadgets.TileApiary;
import forestry.apiculture.gadgets.TileBeehouse;
import forestry.core.config.Defaults;
import forestry.core.gui.GuiForestry;
import forestry.core.utils.EnumTankLevel;
import forestry.core.utils.StringUtil;
import forestry.core.utils.Utils;
public class GuiApiary extends GuiForestry<TileBeehouse> {
public GuiApiary(InventoryPlayer inventory, TileApiary tile) {
super(Defaults.TEXTURE_PATH_GUI + "/apiary.png", new ContainerApiary(inventory, tile, true), tile);
ySize = 190;
}
public GuiApiary(InventoryPlayer inventory, TileBeehouse tile) {
super(Defaults.TEXTURE_PATH_GUI + "/alveary.png", new ContainerApiary(inventory, tile, false), tile);
ySize = 190;
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
String name = StringUtil.localize("tile.for." + tile.getInventoryName());
this.fontRendererObj.drawString(name, getCenteredOffset(name), 6, fontColor.get("gui.title"));
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
TileBeehouse machine = tile;
drawHealthMeter(guiLeft + 20, guiTop + 37, machine.getHealthScaled(46), Utils.rateTankLevel(machine.getHealthScaled(100)));
}
private void drawHealthMeter(int x, int y, int height, EnumTankLevel rated) {
int i = 176;
int k = 0;
switch (rated) {
case EMPTY:
break;
case LOW:
i += 4;
break;
case MEDIUM:
i += 8;
break;
case HIGH:
i += 12;
break;
case MAXIMUM:
i += 16;
break;
}
this.drawTexturedModalRect(x, y + 46 - height, i, k + 46 - height, 4, height);
}
}
+323
View File
@@ -0,0 +1,323 @@
/*******************************************************************************
* 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.gui;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import forestry.api.apiculture.EnumBeeChromosome;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IAlleleBeeEffect;
import forestry.api.apiculture.IBee;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAlleleFlowers;
import forestry.api.genetics.IAlleleInteger;
import forestry.apiculture.items.ItemBeeGE;
import forestry.apiculture.items.ItemBeealyzer.BeealyzerInventory;
import forestry.core.config.ForestryItem;
import forestry.core.genetics.AlleleArea;
import forestry.core.genetics.AlleleBoolean;
import forestry.core.genetics.AlleleTolerance;
import forestry.core.gui.GuiAlyzer;
import forestry.core.utils.StringUtil;
import forestry.core.utils.Vect;
import forestry.plugins.PluginApiculture;
public class GuiBeealyzer extends GuiAlyzer {
private ItemStack[] tempProductList;
public GuiBeealyzer(EntityPlayer player, BeealyzerInventory inventory) {
super(AlleleManager.alleleRegistry.getSpeciesRoot("rootBees"), player,
new ContainerBeealyzer(player.inventory, inventory), inventory, 1, inventory.getSizeInventory());
xSize = 196;
ySize = 238;
ArrayList<ItemStack> beeList = new ArrayList<ItemStack>();
((ItemBeeGE) ForestryItem.beeDroneGE.item()).addCreativeItems(beeList, false);
for (ItemStack beeStack : beeList)
iconStacks.put(PluginApiculture.beeInterface.getMember(beeStack).getIdent(), beeStack);
breedingTracker = PluginApiculture.beeInterface.getBreedingTracker(player.worldObj, player.getGameProfile());
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
int page = 0;
IBee bee = null;
EnumBeeType beeType = EnumBeeType.DRONE;
for (int k = 1; k < BeealyzerInventory.SLOT_ANALYZE_5 + 1; k++) {
if (k == BeealyzerInventory.SLOT_ENERGY)
continue;
if (inventory.getStackInSlot(k) == null)
continue;
bee = PluginApiculture.beeInterface.getMember(inventory.getStackInSlot(k));
beeType = PluginApiculture.beeInterface.getType(inventory.getStackInSlot(k));
if (bee == null || !bee.isAnalyzed())
continue;
page = k;
break;
}
switch (page) {
case 1:
drawAnalyticsPage1(bee, beeType);
break;
case 2:
drawAnalyticsPage2(bee, beeType);
break;
case 3:
drawAnalyticsPage3(bee, beeType);
break;
case 4:
drawAnalyticsPage4(bee);
break;
case 6:
drawAnalyticsPageClassification(bee);
break;
default:
drawAnalyticsOverview();
}
}
private void drawAnalyticsOverview() {
startPage();
newLine();
String title = StringUtil.localize("gui.beealyzer").toUpperCase();
drawCenteredLine(title, 8, 158);
newLine();
fontRendererObj.drawSplitString(StringUtil.localize("gui.beealyzer.help"), (int) ((guiLeft + COLUMN_0 + 4) * (1 / factor)),
(int) ((guiTop + 42) * (1 / factor)), (int) (158 * (1 / factor)), fontColor.get("gui.screen"));
newLine();
newLine();
newLine();
newLine();
drawLine(StringUtil.localize("gui.beealyzer.overview") + ":", COLUMN_0 + 4);
newLine();
drawLine("I : " + StringUtil.localize("gui.general"), COLUMN_0 + 4);
newLine();
drawLine("II : " + StringUtil.localize("gui.environment"), COLUMN_0 + 4);
newLine();
drawLine("III: " + StringUtil.localize("gui.produce"), COLUMN_0 + 4);
newLine();
drawLine("IV : " + StringUtil.localize("gui.evolution"), COLUMN_0 + 4);
newLine();
String mode = breedingTracker.getModeName();
if (mode != null && !mode.isEmpty()) {
newLine();
String rules = StringUtil.localize("gui.beealyzer.behaviour") + ": " + StringUtil.capitalize(mode);
drawLine(rules, 8 + getCenteredOffset(title, 158), fontColor.get("gui.beealyzer.binomial"));
}
endPage();
}
private void drawAnalyticsPage1(IBee bee, EnumBeeType type) {
startPage(COLUMN_0, COLUMN_1, COLUMN_2);
drawLine(StringUtil.localize("gui.active"), COLUMN_1);
drawLine(StringUtil.localize("gui.inactive"), COLUMN_2);
newLine();
newLine();
drawSpeciesRow(StringUtil.localize("gui.species"), bee, EnumBeeChromosome.SPECIES);
drawRow(StringUtil.localize("gui.lifespan"), bee.getGenome().getActiveAllele(EnumBeeChromosome.LIFESPAN.ordinal()).getName(),
bee.getGenome().getInactiveAllele(EnumBeeChromosome.LIFESPAN.ordinal()).getName(), bee,
EnumBeeChromosome.LIFESPAN);
drawRow(StringUtil.localize("gui.speed"), bee.getGenome().getActiveAllele(EnumBeeChromosome.SPEED.ordinal()).getName(),
bee.getGenome().getInactiveAllele(EnumBeeChromosome.SPEED.ordinal()).getName(), bee, EnumBeeChromosome.SPEED);
drawRow(StringUtil.localize("gui.pollination"), bee.getGenome().getActiveAllele(EnumBeeChromosome.FLOWERING.ordinal()).getName(),
bee.getGenome().getInactiveAllele(EnumBeeChromosome.FLOWERING.ordinal()).getName(), bee,
EnumBeeChromosome.FLOWERING);
drawRow(StringUtil.localize("gui.flowers"), StringUtil.localize(bee.getGenome().getFlowerProvider().getDescription()),
StringUtil.localize(((IAlleleFlowers) bee.getGenome().getInactiveAllele(EnumBeeChromosome.FLOWER_PROVIDER.ordinal())).getProvider()
.getDescription()), bee, EnumBeeChromosome.FLOWER_PROVIDER);
drawLine(StringUtil.localize("gui.fertility"), COLUMN_0);
drawFertilityInfo(bee.getGenome().getFertility(), COLUMN_1, getColorCoding(bee.getGenome().getActiveAllele(EnumBeeChromosome.FERTILITY.ordinal())
.isDominant()), 0);
drawFertilityInfo(((IAlleleInteger) bee.getGenome().getInactiveAllele(EnumBeeChromosome.FERTILITY.ordinal())).getValue(), COLUMN_2, getColorCoding(bee
.getGenome().getInactiveAllele(EnumBeeChromosome.FERTILITY.ordinal()).isDominant()), 0);
newLine();
int[] areaAr = bee.getGenome().getTerritory();
Vect area = new Vect(areaAr[0], areaAr[1], areaAr[2]);
drawRow(StringUtil.localize("gui.area"), area.toString(), ((AlleleArea) bee.getGenome().getInactiveAllele(EnumBeeChromosome.TERRITORY.ordinal()))
.getArea().toString(), bee, EnumBeeChromosome.TERRITORY);
drawRow(StringUtil.localize("gui.effect"), StringUtil.localize(bee.getGenome().getEffect().getName()),
StringUtil.localize(((IAlleleBeeEffect) bee.getGenome().getInactiveAllele(EnumBeeChromosome.EFFECT.ordinal())).getName()), bee,
EnumBeeChromosome.EFFECT);
newLine();
endPage();
}
private void drawAnalyticsPage2(IBee bee, EnumBeeType type) {
startPage(COLUMN_0, COLUMN_1, COLUMN_2);
drawLine(StringUtil.localize("gui.active"), COLUMN_1);
drawLine(StringUtil.localize("gui.inactive"), COLUMN_2);
newLine();
newLine();
drawRow(StringUtil.localize("gui.climate"), AlleleManager.climateHelper.toDisplay(bee.getGenome().getPrimary().getTemperature()),
AlleleManager.climateHelper.toDisplay(bee.getGenome().getSecondary().getTemperature()), bee, EnumBeeChromosome.SPECIES);
drawLine(StringUtil.localize("gui.temptol"), COLUMN_0);
drawToleranceInfo(bee.getGenome().getToleranceTemp(), COLUMN_1,
getColorCoding(bee.getGenome().getActiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()).isDominant()));
drawToleranceInfo(((AlleleTolerance) bee.getGenome().getInactiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal())).getValue(), COLUMN_2,
getColorCoding(bee.getGenome().getInactiveAllele(EnumBeeChromosome.TEMPERATURE_TOLERANCE.ordinal()).isDominant()));
newLine();
drawRow(StringUtil.localize("gui.humidity"), AlleleManager.climateHelper.toDisplay(bee.getGenome().getPrimary().getHumidity()),
AlleleManager.climateHelper.toDisplay(bee.getGenome().getSecondary().getHumidity()), bee, EnumBeeChromosome.SPECIES);
drawLine(StringUtil.localize("gui.humidtol"), COLUMN_0);
drawToleranceInfo(bee.getGenome().getToleranceHumid(), COLUMN_1,
getColorCoding(bee.getGenome().getActiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()).isDominant()));
drawToleranceInfo(((AlleleTolerance) bee.getGenome().getInactiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal())).getValue(), COLUMN_2,
getColorCoding(bee.getGenome().getInactiveAllele(EnumBeeChromosome.HUMIDITY_TOLERANCE.ordinal()).isDominant()));
newLine();
newLine();
String yes = StringUtil.localize("yes");
String no = StringUtil.localize("no");
String diurnal0, diurnal1, nocturnal0, nocturnal1;
if(bee.getGenome().getNocturnal()) {
nocturnal0 = diurnal0 = yes;
} else {
nocturnal0 = bee.getGenome().getPrimary().isNocturnal() ? yes : no;
diurnal0 = !bee.getGenome().getPrimary().isNocturnal() ? yes : no;
}
if(((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.NOCTURNAL.ordinal())).getValue()) {
nocturnal1 = diurnal1 = yes;
} else {
nocturnal1 = bee.getGenome().getSecondary().isNocturnal() ? yes : no;
diurnal1 = !bee.getGenome().getSecondary().isNocturnal() ? yes : no;
}
drawLine(StringUtil.localize("gui.diurnal"), COLUMN_0);
drawLine(diurnal0, COLUMN_1, getColorCoding(false));
drawLine(diurnal1, COLUMN_2, getColorCoding(false));
newLine();
drawLine(StringUtil.localize("gui.nocturnal"), COLUMN_0);
drawLine(nocturnal0, COLUMN_1, getColorCoding(false));
drawLine(nocturnal1, COLUMN_2, getColorCoding(false));
newLine();
String primary = StringUtil.readableBoolean(bee.getGenome().getTolerantFlyer(), yes, no);
String secondary = StringUtil.readableBoolean(((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.TOLERANT_FLYER.ordinal())).getValue(), yes,
no);
drawRow(StringUtil.localize("gui.flyer"), primary, secondary, bee, EnumBeeChromosome.TOLERANT_FLYER);
primary = StringUtil.readableBoolean(bee.getGenome().getCaveDwelling(), yes, no);
secondary = StringUtil.readableBoolean(((AlleleBoolean) bee.getGenome().getInactiveAllele(EnumBeeChromosome.CAVE_DWELLING.ordinal())).getValue(), yes,
no);
drawRow(StringUtil.localize("gui.cave"), primary, secondary, bee, EnumBeeChromosome.CAVE_DWELLING);
newLine();
String displayText;
if (type == EnumBeeType.PRINCESS || type == EnumBeeType.QUEEN) {
displayText = "bees.stock.pristine";
if (!bee.isNatural())
displayText = "bees.stock.ignoble";
displayText = StringUtil.localize(displayText);
// int offset = (int)(((158 - fontRendererObj.getStringWidth(origin)) / 2)*(1/factor));
drawCenteredLine(displayText, 8, 158, fontColor.get("gui.beealyzer.binomial"));;
}
if (bee.getGeneration() >= 0) {
newLine();
displayText = bee.getGeneration() + " " + StringUtil.localize("gui.beealyzer.generations");
// offset = (int)(((158 - fontRendererObj.getStringWidth(origin)) / 2)*(1/factor));
drawCenteredLine(displayText, 8, 158, fontColor.get("gui.beealyzer.binomial"));
}
endPage();
}
private void drawAnalyticsPage3(IBee bee, EnumBeeType type) {
tempProductList = bee.getProduceList();
startPage(COLUMN_0, COLUMN_1, COLUMN_2);
drawLine(StringUtil.localize("gui.beealyzer.produce") + ":", COLUMN_0);
newLine();
int x = COLUMN_0;
for (ItemStack stack : tempProductList) {
itemRender.renderItemIntoGUI(fontRendererObj, mc.renderEngine, stack, (int) ((guiLeft + x) * (1 / factor)),
(int) ((guiTop + getLineY()) * (1 / factor)));
x += 18;
if (x > adjustToFactor(148)) {
x = COLUMN_0;
newLine();
}
}
newLine();
newLine();
drawLine(StringUtil.localize("gui.beealyzer.specialty") + ":", COLUMN_0);
newLine();
x = COLUMN_0;
for (ItemStack stack : bee.getSpecialtyList()) {
itemRender.renderItemIntoGUI(fontRendererObj, mc.renderEngine, stack, (int) ((guiLeft + x) * (1 / factor)),
(int) ((guiTop + getLineY()) * (1 / factor)));
x += 18;
if (x > adjustToFactor(148)) {
x = COLUMN_0;
newLine();
}
}
endPage();
}
}
@@ -0,0 +1,192 @@
/*******************************************************************************
* 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.gui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.IIcon;
import net.minecraft.world.biome.BiomeGenBase;
import org.lwjgl.opengl.GL11;
import forestry.apiculture.items.ItemBiomefinder.BiomefinderInventory;
import forestry.core.config.Defaults;
import forestry.core.gadgets.TileForestry;
import forestry.core.gui.GuiForestry;
import forestry.core.gui.widgets.Widget;
import forestry.core.proxy.Proxies;
import forestry.core.render.SpriteSheet;
import forestry.core.render.TextureManager;
import forestry.core.utils.StringUtil;
public class GuiHabitatLocator extends GuiForestry<TileForestry> {
public class HabitatSlot extends Widget {
private final int slot;
private final String name;
private final String iconIndex;
public boolean isActive = false;
public HabitatSlot(int slot, String name) {
super(widgetManager, 0, 0);
this.slot = slot;
this.name = name;
this.iconIndex = "habitats/" + name.toLowerCase(Locale.ENGLISH);
}
@Override
public String getLegacyTooltip(EntityPlayer player) {
return name;
}
public IIcon getIcon() {
return TextureManager.getInstance().getDefault(iconIndex);
}
public void setPosition(int x, int y) {
this.xPos = x;
this.yPos = y;
}
@Override
public void draw(int startX, int startY) {
if (getIcon() != null) {
GL11.glDisable(GL11.GL_LIGHTING);
if (!isActive)
GL11.glColor4f(0.2f, 0.2f, 0.2f, 0.2f);
Proxies.common.bindTexture(SpriteSheet.ITEMS);
manager.gui.drawTexturedModelRectFromIcon(startX + xPos, startY + yPos, getIcon(), 16, 16);
GL11.glEnable(GL11.GL_LIGHTING);
}
}
}
private final HabitatSlot[] habitatSlots = new HabitatSlot[] { new HabitatSlot(0, "Ocean"), // ocean
// +
// beach
new HabitatSlot(1, "Plains"), new HabitatSlot(2, "Desert"), // desert
// +
// desert
// hills
new HabitatSlot(3, "Forest"), // forest, forestHills, river
new HabitatSlot(4, "Jungle"), // jungle, jungleHills
new HabitatSlot(5, "Taiga"), // taiga, taigaHills
new HabitatSlot(6, "Hills"), // extremeHills, extremeHillsEdge
new HabitatSlot(7, "Swampland"), new HabitatSlot(8, "Snow"), // Ice
// plains,
// mountains,
// frozen
// rivers,
// frozen
// oceans
new HabitatSlot(9, "Mushroom"), // Ice plains, mountains, frozen
// rivers, frozen oceans
new HabitatSlot(10, "Hell"), new HabitatSlot(11, "End") };
private final HashMap<Integer, HabitatSlot> biomeToHabitat = new HashMap<Integer, HabitatSlot>();
private int startX;
private int startY;
public GuiHabitatLocator(InventoryPlayer inventory, BiomefinderInventory item) {
super(Defaults.TEXTURE_PATH_GUI + "/biomefinder.png", new ContainerHabitatLocator(inventory, item), item);
xSize = 176;
ySize = 184;
int x;
int y;
for (HabitatSlot slot : habitatSlots) {
if (slot.slot > 5) {
x = 18 + (slot.slot - 6) * 20;
y = 50;
} else {
x = 18 + slot.slot * 20;
y = 32;
}
slot.setPosition(x, y);
this.widgetManager.add(slot);
}
biomeToHabitat.put(BiomeGenBase.ocean.biomeID, habitatSlots[0]);
biomeToHabitat.put(BiomeGenBase.beach.biomeID, habitatSlots[0]);
biomeToHabitat.put(BiomeGenBase.plains.biomeID, habitatSlots[1]);
biomeToHabitat.put(BiomeGenBase.desert.biomeID, habitatSlots[2]);
// biomeToHabitat.put(BiomeGenBase.desertHills.biomeID,
// habitatSlots[2]); // Removed for TFC compatibility
biomeToHabitat.put(BiomeGenBase.forest.biomeID, habitatSlots[3]);
biomeToHabitat.put(BiomeGenBase.forestHills.biomeID, habitatSlots[3]);
biomeToHabitat.put(BiomeGenBase.river.biomeID, habitatSlots[3]);
biomeToHabitat.put(BiomeGenBase.jungle.biomeID, habitatSlots[4]);
biomeToHabitat.put(BiomeGenBase.jungleHills.biomeID, habitatSlots[4]);
biomeToHabitat.put(BiomeGenBase.taiga.biomeID, habitatSlots[5]);
biomeToHabitat.put(BiomeGenBase.taigaHills.biomeID, habitatSlots[5]);
biomeToHabitat.put(BiomeGenBase.extremeHills.biomeID, habitatSlots[6]);
biomeToHabitat.put(BiomeGenBase.extremeHillsEdge.biomeID, habitatSlots[6]);
biomeToHabitat.put(BiomeGenBase.swampland.biomeID, habitatSlots[7]);
biomeToHabitat.put(BiomeGenBase.frozenOcean.biomeID, habitatSlots[8]);
biomeToHabitat.put(BiomeGenBase.frozenRiver.biomeID, habitatSlots[8]);
biomeToHabitat.put(BiomeGenBase.iceMountains.biomeID, habitatSlots[8]);
biomeToHabitat.put(BiomeGenBase.icePlains.biomeID, habitatSlots[8]);
biomeToHabitat.put(BiomeGenBase.mushroomIsland.biomeID, habitatSlots[9]);
biomeToHabitat.put(BiomeGenBase.mushroomIslandShore.biomeID, habitatSlots[9]);
biomeToHabitat.put(BiomeGenBase.hell.biomeID, habitatSlots[10]);
biomeToHabitat.put(BiomeGenBase.sky.biomeID, habitatSlots[11]);
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
String str = StringUtil.localize("gui.habitatlocator").toUpperCase();
fontRendererObj.drawString(str, startX + 8 + getCenteredOffset(str, 138), startY + 16, fontColor.get("gui.screen"));
str = "(" + StringUtil.localize("gui.closetosearch") + ")";
fontRendererObj.drawString(str, startX + 8 + getCenteredOffset(str, 138), startY + 76, fontColor.get("gui.table.header"));
// Reset habitat slots
for (HabitatSlot slot : habitatSlots)
slot.isActive = false;
// Set according to valid biomes.
ArrayList<Integer> biomeids = ((ContainerHabitatLocator) inventorySlots).inventory.biomesToSearch;
for (int biomeid : biomeids) {
if (!biomeToHabitat.containsKey(biomeid))
continue;
biomeToHabitat.get(biomeid).isActive = true;
}
for (HabitatSlot slot : habitatSlots)
slot.draw(startX, startY);
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Reset afterwards.
}
@Override
public void initGui() {
super.initGui();
startX = (this.width - this.xSize) / 2;
startY = (this.height - this.ySize) / 2;
}
}
+130
View File
@@ -0,0 +1,130 @@
/*******************************************************************************
* 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.gui;
import java.util.ArrayList;
import java.util.HashMap;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.apiculture.items.ItemBeeGE;
import forestry.apiculture.items.ItemImprinter.ImprinterInventory;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryItem;
import forestry.core.gadgets.TileForestry;
import forestry.core.gui.GuiForestry;
import forestry.core.proxy.Proxies;
import forestry.plugins.PluginApiculture;
public class GuiImprinter extends GuiForestry<TileForestry> {
private final ImprinterInventory inventory;
private final ContainerImprinter container;
private int startX;
private int startY;
private final HashMap<String, ItemStack> iconStacks = new HashMap<String, ItemStack>();
public GuiImprinter(InventoryPlayer inventoryplayer, ImprinterInventory inventory) {
super(Defaults.TEXTURE_PATH_GUI + "/imprinter.png", new ContainerImprinter(inventoryplayer, inventory), inventory);
this.inventory = inventory;
this.container = (ContainerImprinter) inventorySlots;
xSize = 176;
ySize = 185;
ArrayList<ItemStack> beeList = new ArrayList<ItemStack>();
((ItemBeeGE) ForestryItem.beeDroneGE.item()).addCreativeItems(beeList, false);
for (ItemStack beeStack : beeList)
iconStacks.put(PluginApiculture.beeInterface.getMember(beeStack).getIdent(), beeStack);
}
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
container.updateContainer(Proxies.common.getRenderWorld());
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
int offset = (138 - fontRendererObj.getStringWidth("GENOME IMPRINTER")) / 2;
fontRendererObj.drawString("GENOME IMPRINTER", startX + 8 + offset, startY + 16, fontColor.get("gui.screen"));
IAlleleBeeSpecies primary = inventory.getPrimary();
drawBeeSpeciesIcon(primary, startX + 12, startY + 32);
fontRendererObj.drawString(primary.getName(), startX + 32, startY + 36, fontColor.get("gui.screen"));
IAlleleBeeSpecies secondary = inventory.getSecondary();
drawBeeSpeciesIcon(secondary, startX + 12, startY + 52);
fontRendererObj.drawString(secondary.getName(), startX + 32, startY + 56, fontColor.get("gui.screen"));
String youCheater = "(You Cheater!)";
offset = (138 - fontRendererObj.getStringWidth(youCheater)) / 2;
fontRendererObj.drawString(youCheater, startX + 8 + offset, startY + 76, fontColor.get("gui.screen"));
}
private void drawBeeSpeciesIcon(IAlleleBeeSpecies bee, int x, int y) {
/*
* GL11.glDisable(GL11.GL_LIGHTING); mc.renderEngine.func_98187_b(Defaults.TEXTURE_BEES);
*
* for (int i = 0; i < ForestryItem.beeDroneGE.getRenderPasses(0); ++i) {
*
* int iconIndex = ForestryItem.beeDroneGE.getIconIndex(iconStacks.get(bee.getUID()), i); int color = ((ItemGE)
* ForestryItem.beeDroneGE).getColorFromItemStack(iconStacks.get(bee.getUID()), i); float colorR = (color >> 16 & 255) / 255.0F; float colorG = (color
* >> 8 & 255) / 255.0F; float colorB = (color & 255) / 255.0F;
*
* GL11.glColor4f(colorR, colorG, colorB, 1.0F); drawTexturedModalRect(x, y, iconIndex % 16 * 16, iconIndex / 16 * 16, 16, 16);
*
* } GL11.glEnable(GL11.GL_LIGHTING);
*/
}
private int getHabitatSlotAtPosition(int i, int j) {
int[] xPos = new int[] { 12, 12 };
int[] yPos = new int[] { 32, 52 };
for (int l = 0; l < xPos.length; l++)
if (i >= xPos[l] && i <= xPos[l] + 16 && j >= yPos[l] && j <= yPos[l] + 16)
return l;
return -1;
}
@Override
protected void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
int slot = 0;
if ((slot = getHabitatSlotAtPosition(i - cornerX, j - cornerY)) < 0)
return;
if (k == 0)
container.advanceSelection(slot, Proxies.common.getRenderWorld());
else
container.regressSelection(slot, Proxies.common.getRenderWorld());
}
@Override
public void initGui() {
super.initGui();
startX = (this.width - this.xSize) / 2;
startY = (this.height - this.ySize) / 2;
}
}
@@ -0,0 +1,27 @@
/*******************************************************************************
* 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.items;
import net.minecraft.block.Block;
import forestry.core.gadgets.IStructureBlockItem;
import forestry.core.items.ItemForestryBlock;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class ItemAlvearyBlock extends ItemForestryBlock implements IStructureBlockItem {
public ItemAlvearyBlock(Block block) {
super(block);
}
}
@@ -0,0 +1,128 @@
/*******************************************************************************
* 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.items;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.apiculture.IArmorApiarist;
import forestry.api.core.IArmorNaturalist;
import forestry.api.core.Tabs;
import forestry.core.config.Defaults;
import forestry.core.config.ForestryItem;
import forestry.core.render.TextureManager;
import forestry.core.utils.StringUtil;
public class ItemArmorApiarist extends ItemArmor implements IArmorApiarist, IArmorNaturalist {
public ItemArmorApiarist(int slot) {
super(ArmorMaterial.CLOTH, 0, slot);
this.setMaxDamage(100);
setCreativeTab(Tabs.tabApiculture);
}
@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
if (ForestryItem.apiaristLegs.isItemEqual(stack))
return Defaults.ID + ":" + Defaults.TEXTURE_APIARIST_ARMOR_SECONDARY;
else
return Defaults.ID + ":" + Defaults.TEXTURE_APIARIST_ARMOR_PRIMARY;
}
@Override
public String getItemStackDisplayName(ItemStack itemstack) {
return StringUtil.localize(getUnlocalizedName(itemstack));
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister register) {
itemIcon = TextureManager.getInstance().registerTex(register, getUnlocalizedName().replace("item.", ""));
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIconFromDamageForRenderPass(int par1, int par2) {
return itemIcon;
}
@Override
public boolean requiresMultipleRenderPasses() {
return false;
}
@Override
public int getColorFromItemStack(ItemStack itemstack, int renderPass) {
return 0xffffff;
}
@Override
public boolean hasColor(ItemStack itemstack) {
return false;
}
@Override
public boolean protectPlayer(EntityPlayer player, ItemStack armor, String cause, boolean doProtect) {
return true;
}
@Override
public boolean canSeePollination(EntityPlayer player, ItemStack armor, boolean doSee) {
return armorType == 0;
}
public static boolean wearsHelmet(EntityPlayer player, String cause, boolean protect) {
ItemStack armorItem = player.inventory.armorInventory[3];
return armorItem != null && armorItem.getItem() instanceof IArmorApiarist
&& ((IArmorApiarist) armorItem.getItem()).protectPlayer(player, armorItem, cause, protect);
}
public static boolean wearsChest(EntityPlayer player, String cause, boolean protect) {
ItemStack armorItem = player.inventory.armorInventory[2];
return armorItem != null && armorItem.getItem() instanceof IArmorApiarist
&& ((IArmorApiarist) armorItem.getItem()).protectPlayer(player, armorItem, cause, protect);
}
public static boolean wearsLegs(EntityPlayer player, String cause, boolean protect) {
ItemStack armorItem = player.inventory.armorInventory[1];
return armorItem != null && armorItem.getItem() instanceof IArmorApiarist
&& ((IArmorApiarist) armorItem.getItem()).protectPlayer(player, armorItem, cause, protect);
}
public static boolean wearsBoots(EntityPlayer player, String cause, boolean protect) {
ItemStack armorItem = player.inventory.armorInventory[0];
return armorItem != null && armorItem.getItem() instanceof IArmorApiarist
&& ((IArmorApiarist) armorItem.getItem()).protectPlayer(player, armorItem, cause, protect);
}
public static int wearsItems(EntityPlayer player, String cause, boolean protect) {
int count = 0;
if (wearsHelmet(player, cause, protect))
count++;
if (wearsChest(player, cause, protect))
count++;
if (wearsLegs(player, cause, protect))
count++;
if (wearsBoots(player, cause, protect))
count++;
return count;
}
}
+171
View File
@@ -0,0 +1,171 @@
/*******************************************************************************
* 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.items;
import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.apiculture.EnumBeeChromosome;
import forestry.api.apiculture.EnumBeeType;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBee;
import forestry.api.core.Tabs;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IAllele;
import forestry.api.genetics.IAlleleSpecies;
import forestry.api.genetics.IIndividual;
import forestry.apiculture.genetics.Bee;
import forestry.core.config.Config;
import forestry.core.genetics.ItemGE;
import forestry.core.utils.StringUtil;
import forestry.plugins.PluginApiculture;
public class ItemBeeGE extends ItemGE {
EnumBeeType type;
public ItemBeeGE(EnumBeeType type) {
super();
this.type = type;
setCreativeTab(Tabs.tabApiculture);
if (type != EnumBeeType.DRONE)
setMaxStackSize(1);
}
@Override
protected IIndividual getIndividual(ItemStack itemstack) {
return new Bee(itemstack.getTagCompound());
}
@Override
protected int getDefaultPrimaryColour() {
return 0xffffff;
}
@Override
protected int getDefaultSecondaryColour() {
return 0xffdc16;
}
@Override
public String getItemStackDisplayName(ItemStack itemstack) {
if (itemstack.getTagCompound() == null)
return StringUtil.localize(type.getName());
IBee individual = new Bee(itemstack.getTagCompound());
return individual.getDisplayName() + StringUtil.localize(type.getName() + ".adj.add") + " " + StringUtil.localize(type.getName());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) {
if(!itemstack.hasTagCompound())
return;
if(type != EnumBeeType.DRONE) {
IBee individual = new Bee(itemstack.getTagCompound());
if (individual.isNatural())
list.add("\u00A7e\u00A7o" + StringUtil.localize("bees.stock.pristine"));
else
list.add("\u00A7e" + StringUtil.localize("bees.stock.ignoble"));
}
super.addInformation(itemstack, player, list, flag);
}
@SuppressWarnings("rawtypes")
@Override
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
if (type == EnumBeeType.QUEEN)
return;
addCreativeItems(itemList, true);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public void addCreativeItems(List itemList, boolean hideSecrets) {
for (IIndividual individual : PluginApiculture.beeInterface.getIndividualTemplates()) {
// Don't show secret bees unless ordered to.
if (hideSecrets && individual.isSecret() && !Config.isDebug)
continue;
NBTTagCompound nbttagcompound = new NBTTagCompound();
ItemStack someStack = new ItemStack(this);
individual.writeToNBT(nbttagcompound);
someStack.setTagCompound(nbttagcompound);
itemList.add(someStack);
}
}
/* RENDERING */
@Override
public int getColorFromItemStack(ItemStack itemstack, int renderPass) {
if (!itemstack.hasTagCompound())
return super.getColorFromItemStack(itemstack, renderPass);
return getColourFromSpecies(PluginApiculture.beeInterface.getMember(itemstack).getGenome().getPrimary(), renderPass);
}
@Override
public int getColourFromSpecies(IAlleleSpecies species, int renderPass) {
if (species != null && species instanceof IAlleleBeeSpecies)
return ((IAlleleBeeSpecies) species).getIconColour(renderPass);
else
return 0xffffff;
}
@Override
public boolean requiresMultipleRenderPasses() {
return true;
}
@Override
public int getRenderPasses(int metadata) {
return 3;
}
/* ICONS */
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister register) {
for (IAllele allele : AlleleManager.alleleRegistry.getRegisteredAlleles().values())
if (allele instanceof IAlleleBeeSpecies)
((IAlleleBeeSpecies) allele).getIconProvider().registerIcons(register);
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon(ItemStack itemstack, int renderPass) {
return getIconFromSpecies(PluginApiculture.beeInterface.getMember(itemstack).getGenome().getPrimary(), renderPass);
}
@SideOnly(Side.CLIENT)
public IIcon getIconFromSpecies(IAlleleBeeSpecies species, int renderPass) {
if (species == null)
species = (IAlleleBeeSpecies) PluginApiculture.beeInterface.getDefaultTemplate()[EnumBeeChromosome.SPECIES.ordinal()];
return species.getIcon(type, renderPass);
}
}
+167
View File
@@ -0,0 +1,167 @@
/*******************************************************************************
* 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.items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import forestry.api.apiculture.IBee;
import forestry.api.core.ForestryAPI;
import forestry.api.core.Tabs;
import forestry.core.EnumErrorCode;
import forestry.core.config.Config;
import forestry.core.config.ForestryItem;
import forestry.core.interfaces.IErrorSource;
import forestry.core.interfaces.IHintSource;
import forestry.core.items.ItemInventoried;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.utils.ItemInventory;
import forestry.plugins.PluginApiculture;
public class ItemBeealyzer extends ItemInventoried {
public static class BeealyzerInventory extends ItemInventory implements IErrorSource, IHintSource {
public static final int SLOT_SPECIMEN = 0;
public static final int SLOT_ANALYZE_1 = 1;
public static final int SLOT_ANALYZE_2 = 2;
public static final int SLOT_ANALYZE_3 = 3;
public static final int SLOT_ANALYZE_4 = 4;
public static final int SLOT_ANALYZE_5 = 6;
public static final int SLOT_ENERGY = 5;
EntityPlayer player;
public BeealyzerInventory(EntityPlayer player) {
super(ItemBeealyzer.class, 7);
this.player = player;
}
public BeealyzerInventory(EntityPlayer player, ItemStack itemStack) {
super(ItemBeealyzer.class, 7, itemStack);
this.player = player;
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
NBTTagList nbttaglist = new NBTTagList();
for (int i = SLOT_ENERGY; i < SLOT_ENERGY + 1; i++)
if (inventoryStacks[i] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
inventoryStacks[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
nbttagcompound.setTag("Items", nbttaglist);
}
private boolean isEnergy(ItemStack itemstack) {
if (itemstack == null || itemstack.stackSize <= 0)
return false;
return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack);
}
private void tryAnalyze() {
// Analyzed slot occupied, abort
if (inventoryStacks[SLOT_ANALYZE_1] != null || inventoryStacks[SLOT_ANALYZE_2] != null || inventoryStacks[SLOT_ANALYZE_3] != null
|| inventoryStacks[SLOT_ANALYZE_4] != null || inventoryStacks[SLOT_ANALYZE_5] != null)
return;
// Source slot to analyze empty
if (getStackInSlot(SLOT_SPECIMEN) == null)
return;
IBee bee = PluginApiculture.beeInterface.getMember(getStackInSlot(SLOT_SPECIMEN));
// No bee, abort
if (bee == null)
return;
// Analyze if necessary
if (!bee.isAnalyzed()) {
// Requires energy
if (!isEnergy(getStackInSlot(SLOT_ENERGY)))
return;
bee.analyze();
if(player != null) {
PluginApiculture.beeInterface.getBreedingTracker(player.worldObj, player.getGameProfile()).registerSpecies(bee.getGenome().getPrimary());
PluginApiculture.beeInterface.getBreedingTracker(player.worldObj, player.getGameProfile()).registerSpecies(bee.getGenome().getSecondary());
}
NBTTagCompound nbttagcompound = new NBTTagCompound();
bee.writeToNBT(nbttagcompound);
getStackInSlot(SLOT_SPECIMEN).setTagCompound(nbttagcompound);
// Decrease energy
decrStackSize(SLOT_ENERGY, 1);
}
setInventorySlotContents(SLOT_ANALYZE_1, getStackInSlot(SLOT_SPECIMEN));
setInventorySlotContents(SLOT_SPECIMEN, null);
}
@Override
public void markDirty() {
// if (!Proxies.common.isSimulating(player.worldObj))
// return;
tryAnalyze();
}
// / IHINTSOURCE
@Override
public boolean hasHints() {
return Config.hints.get("beealyzer") != null && Config.hints.get("beealyzer").length > 0;
}
@Override
public String[] getHints() {
return Config.hints.get("beealyzer");
}
// / IERRORSOURCE
@Override
public boolean throwsErrors() {
return true;
}
@Override
public EnumErrorCode getErrorState() {
if (PluginApiculture.beeInterface.isMember(inventoryStacks[SLOT_SPECIMEN]) && !isEnergy(getStackInSlot(SLOT_ENERGY)))
return EnumErrorCode.NOHONEY;
return EnumErrorCode.OK;
}
}
public ItemBeealyzer() {
super();
setMaxStackSize(1);
setCreativeTab(Tabs.tabApiculture);
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
if (Proxies.common.isSimulating(world))
entityplayer.openGui(ForestryAPI.instance, GuiId.BeealyzerGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY,
(int) entityplayer.posZ);
return itemstack;
}
}
@@ -0,0 +1,240 @@
/*******************************************************************************
* 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.items;
import java.util.ArrayList;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.apiculture.IBee;
import forestry.api.core.ForestryAPI;
import forestry.api.core.Tabs;
import forestry.apiculture.render.TextureBiomefinder;
import forestry.core.EnumErrorCode;
import forestry.core.config.Config;
import forestry.core.config.ForestryItem;
import forestry.core.interfaces.IErrorSource;
import forestry.core.interfaces.IHintSource;
import forestry.core.items.ItemInventoried;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.core.utils.ItemInventory;
import forestry.core.utils.Vect;
import forestry.plugins.PluginApiculture;
public class ItemBiomefinder extends ItemInventoried {
public static class BiomefinderInventory extends ItemInventory implements IErrorSource, IHintSource {
public ArrayList<Integer> biomesToSearch = new ArrayList<Integer>();
private final short energySlot = 2;
private final short specimenSlot = 0;
private final short analyzeSlot = 1;
public BiomefinderInventory() {
super(ItemBiomefinder.class, 3);
}
public BiomefinderInventory(ItemStack itemstack) {
super(ItemBiomefinder.class, 3, itemstack);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
NBTTagList nbttaglist = new NBTTagList();
for (int i = 2; i < inventoryStacks.length; i++)
if (inventoryStacks[i] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
inventoryStacks[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
nbttagcompound.setTag("Items", nbttaglist);
}
private boolean isEnergy(ItemStack itemstack) {
if (itemstack == null || itemstack.stackSize <= 0)
return false;
return ForestryItem.honeyDrop.isItemEqual(itemstack) || ForestryItem.honeydew.isItemEqual(itemstack);
}
private void tryAnalyze() {
// Analyzed slot occupied, abort
if (inventoryStacks[analyzeSlot] != null)
return;
// Source slot to analyze empty
if (getStackInSlot(specimenSlot) == null)
return;
IBee bee = PluginApiculture.beeInterface.getMember(getStackInSlot(specimenSlot));
// No bee, abort
if (bee == null)
return;
// Requires energy
if (!isEnergy(getStackInSlot(energySlot)))
return;
biomesToSearch = bee.getSuitableBiomeIds();
// Decrease energy
decrStackSize(energySlot, 1);
setInventorySlotContents(analyzeSlot, getStackInSlot(specimenSlot));
setInventorySlotContents(specimenSlot, null);
}
@Override
public void markDirty() {
tryAnalyze();
}
// / IHINTSOURCE
@Override
public boolean hasHints() {
return Config.hints.get("habitatlocator") != null && Config.hints.get("habitatlocator").length > 0;
}
@Override
public String[] getHints() {
return Config.hints.get("habitatlocator");
}
// / IERRORSOURCE
@Override
public boolean throwsErrors() {
return true;
}
@Override
public EnumErrorCode getErrorState() {
if (PluginApiculture.beeInterface.isMember(inventoryStacks[specimenSlot]) && !isEnergy(getStackInSlot(energySlot)))
return EnumErrorCode.NOHONEY;
return EnumErrorCode.OK;
}
}
public ItemBiomefinder() {
super();
setMaxStackSize(1);
setCreativeTab(Tabs.tabApiculture);
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
if (Proxies.common.isSimulating(world))
entityplayer.openGui(ForestryAPI.instance, GuiId.HabitatLocatorGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY,
(int) entityplayer.posZ);
return itemstack;
}
public void startBiomeSearch(World world, EntityPlayer player, ArrayList<Integer> biomesToSearch) {
ArrayList<Integer> excludedBiomes = new ArrayList<Integer>();
excludedBiomes.add(BiomeGenBase.ocean.biomeID);
excludedBiomes.add(BiomeGenBase.frozenOcean.biomeID);
excludedBiomes.add(BiomeGenBase.beach.biomeID);
biomesToSearch.removeAll(excludedBiomes);
// If we are in a valid biome, we point to ourself.
BiomeGenBase biome = world.getBiomeGenForCoords((int) player.posX, (int) player.posZ);
if (biomesToSearch.contains(biome.biomeID)) {
Proxies.common.setBiomefinderCoordinates(player, new ChunkCoordinates((int) player.posX, (int) player.posY, (int) player.posZ));
return;
}
if (Proxies.common.isSimulating(world) && biomesToSearch.size() > 0) {
ChunkCoordinates target = findNearestBiome(player, biomesToSearch);
Proxies.common.setBiomefinderCoordinates(player, target);
}
}
private ChunkCoordinates findNearestBiome(EntityPlayer player, ArrayList<Integer> biomesToSearch) {
int loadChunkDistance = 25;
ChunkCoordinates coordinates = null;
Vect pos = new Vect((int) player.posX, (int) player.posY, (int) player.posZ);
for (int i = 0; i < 100; i++) {
// Test direction +X
if ((coordinates = getChunkCoordinates(pos.add(new Vect(10 * i, 0, 0)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null)
return coordinates;
// Test direction +X+Z
if ((coordinates = getChunkCoordinates(pos.add(new Vect(10 * i, 0, 10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null)
return coordinates;
// Test direction +X-Z
if ((coordinates = getChunkCoordinates(pos.add(new Vect(10 * i, 0, -10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null)
return coordinates;
// Test direction -X
if ((coordinates = getChunkCoordinates(pos.add(new Vect(-10 * i, 0, 0)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null)
return coordinates;
// Test direction -X+Z
if ((coordinates = getChunkCoordinates(pos.add(new Vect(-10 * i, 0, 10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null)
return coordinates;
// Test direction -X-Z
if ((coordinates = getChunkCoordinates(pos.add(new Vect(-10 * i, 0, -10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null)
return coordinates;
// Test direction +Z
if ((coordinates = getChunkCoordinates(pos.add(new Vect(0, 0, 10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null)
return coordinates;
// Test direction -Z
if ((coordinates = getChunkCoordinates(pos.add(new Vect(0, 0, -10 * i)), player.worldObj, biomesToSearch, i < loadChunkDistance)) != null)
return coordinates;
}
return coordinates;
}
private ChunkCoordinates getChunkCoordinates(Vect pos, World world, ArrayList<Integer> biomesToSearch, boolean loadChunks) {
BiomeGenBase biome = world.getBiomeGenForCoords(pos.x, pos.z);
if (biomesToSearch.contains(biome.biomeID))
return new ChunkCoordinates(pos.x, pos.y, pos.z);
return null;
}
/* TEXTURES */
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister register) {
if(register instanceof TextureMap) {
TextureAtlasSprite texture = new TextureBiomefinder();
((TextureMap)register).setTextureEntry("forestry:biomefinder", texture);
itemIcon = texture;
}
}
}
@@ -0,0 +1,76 @@
/*******************************************************************************
* 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.items;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.apiculture.gadgets.BlockCandle;
import forestry.core.items.ItemForestryBlock;
public class ItemCandleBlock extends ItemForestryBlock {
public ItemCandleBlock(Block block) {
super(block);
}
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int pass) {
int value = 0xffffff;
if (pass == 1 && stack.hasTagCompound()) {
NBTTagCompound tag = stack.getTagCompound();
if (tag.hasKey("colour")) {
value = tag.getInteger("colour");
}
}
return value;
}
@Override
public String getUnlocalizedName(ItemStack itemStack) {
String value = "tile.candle";
if (itemStack.hasTagCompound() && itemStack.getTagCompound().hasKey(BlockCandle.colourTagName)) {
value = value + ".dyed";
}
if (BlockCandle.isLit(itemStack)) {
value = value + ".lit";
}
else {
value = value + ".stump";
}
return value;
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamageForRenderPass(int meta, int pass) {
return ((BlockCandle)this.getBlock()).getTextureFromPassAndMeta((meta != 0) ? 8 : 0, pass);
}
@Override
@SideOnly(Side.CLIENT)
public boolean requiresMultipleRenderPasses() {
return true;
}
@Override
public int getRenderPasses(int metadata) {
return 2;
}
}
+98
View File
@@ -0,0 +1,98 @@
/*******************************************************************************
* 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.items;
import net.minecraft.item.ItemStack;
import forestry.api.apiculture.IBee;
import forestry.api.apiculture.IBeeGenome;
import forestry.api.apiculture.IBeeHousing;
import forestry.api.apiculture.IHiveFrame;
import forestry.api.core.Tabs;
import forestry.core.items.ItemForestry;
public class ItemHiveFrame extends ItemForestry implements IHiveFrame {
private final float geneticDecay;
public ItemHiveFrame(int maxDamage, float geneticDecay) {
super();
setMaxStackSize(1);
setMaxDamage(maxDamage);
this.geneticDecay = geneticDecay;
setCreativeTab(Tabs.tabApiculture);
}
@Override
public ItemStack frameUsed(IBeeHousing housing, ItemStack frame, IBee queen, int wear) {
frame.setItemDamage(frame.getItemDamage() + wear);
if (frame.getItemDamage() >= frame.getMaxDamage())
return null;
else
return frame;
}
@Override
public float getTerritoryModifier(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public float getMutationModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
return 1.0f;
}
@Override
public float getLifespanModifier(IBeeGenome genome, IBeeGenome mate, float currentModifier) {
return 1.0f;
}
@Override
public float getProductionModifier(IBeeGenome genome, float currentModifier) {
return currentModifier < 10f ? 2.0f : 1f;
}
@Override
public float getFloweringModifier(IBeeGenome genome, float currentModifier) {
return 1.0f;
}
@Override
public float getGeneticDecay(IBeeGenome genome, float currentModifier) {
return this.geneticDecay;
}
@Override
public boolean isSealed() {
return false;
}
@Override
public boolean isSelfLighted() {
return false;
}
@Override
public boolean isSunlightSimulated() {
return false;
}
@Override
public boolean isHellish() {
return false;
}
@Override
public boolean isBookEnchantable(ItemStack itemstack1, ItemStack itemstack2) {
return false;
}
}
+161
View File
@@ -0,0 +1,161 @@
/*******************************************************************************
* 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.items;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import forestry.api.core.Tabs;
import forestry.core.config.Config;
import forestry.core.config.ForestryItem;
import forestry.core.items.ItemForestry;
import forestry.core.render.TextureManager;
import forestry.core.utils.StringUtil;
public class ItemHoneycomb extends ItemForestry {
private static class CombInfo {
public String name;
public int primaryColor;
public int secondaryColor;
public boolean isSecret = false;
public CombInfo(String name, int primaryColor, int secondaryColor) {
this.name = name;
this.primaryColor = primaryColor;
this.secondaryColor = secondaryColor;
}
public CombInfo setIsSecret() {
this.isSecret = true;
return this;
}
}
public CombInfo[] combs = new CombInfo[] { new CombInfo("honey", 0xe8d56a, 0xffa12b), // 0
new CombInfo("cocoa", 0x674016, 0xffb62b).setIsSecret(), // 1
new CombInfo("simmering", 0x981919, 0xffb62b), // 2
new CombInfo("stringy", 0xc8be67, 0xbda93e), // 3
new CombInfo("frozen", 0xf9ffff, 0xa0ffff), // 4
new CombInfo("dripping", 0xdc7613, 0xffff00), // 5
new CombInfo("silky", 0x508907, 0xddff00), // 6
new CombInfo("parched", 0xdcbe13, 0xffff00), // 7
new CombInfo("mysterious", 0x161616, 0xe099ff).setIsSecret(), // 8
new CombInfo("irradiated", 0xeafff3, 0xeeff00).setIsSecret(), // 9
new CombInfo("powdery", 0xe4e4e4, 0xffffff).setIsSecret(), // 10
new CombInfo("reddened", 0x4b0000, 0x6200e7).setIsSecret(), // 11
new CombInfo("darkened", 0x353535, 0x33ebcb).setIsSecret(), // 12
new CombInfo("omega", 0x191919, 0x6dcff6).setIsSecret(), // 13
new CombInfo("wheaten", 0xfeff8f, 0xffffff).setIsSecret(), // 14
new CombInfo("mossy", 0x2a3313, 0x7e9939), // 15
new CombInfo("mellow", 0x886000, 0xfff960) // 16
// new CombInfo("", 0xd7bee5, 0xfd58ab), // kindof pinkish
};
public ItemHoneycomb() {
super();
setMaxDamage(0);
setHasSubtypes(true);
setCreativeTab(Tabs.tabApiculture);
}
@Override
public boolean isDamageable() {
return false;
}
@Override
public boolean isRepairable() {
return false;
}
@Override
public String getItemStackDisplayName(ItemStack itemstack) {
if (itemstack.getItemDamage() < 0 || itemstack.getItemDamage() >= combs.length)
return null;
return StringUtil.localize("item.comb." + combs[itemstack.getItemDamage()].name);
}
/* ICONS */
@SideOnly(Side.CLIENT)
private IIcon[] icons;
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister register) {
icons = new IIcon[2];
icons[0] = TextureManager.getInstance().registerTex(register, getUnlocalizedName().replace("item.", "") + ".0");
icons[1] = TextureManager.getInstance().registerTex(register, getUnlocalizedName().replace("item.", "") + ".1");
}
@SideOnly(Side.CLIENT)
@Override
public IIcon getIconFromDamageForRenderPass(int i, int j) {
if (j > 0)
return icons[0];
else
return icons[1];
}
@Override
public boolean requiresMultipleRenderPasses() {
return true;
}
@Override
public int getColorFromItemStack(ItemStack itemstack, int j) {
if (j == 0)
return combs[itemstack.getItemDamage()].primaryColor;
else
return combs[itemstack.getItemDamage()].secondaryColor;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void getSubItems(Item item, CreativeTabs par2CreativeTabs, List itemList) {
for (int i = 0; i < combs.length; i++) {
if (!combs[i].isSecret || Config.isDebug)
itemList.add(new ItemStack(this, 1, i));
}
}
public int getCombTypeCount() {
return combs.length;
}
public int getRandomCombType(Random random, boolean includeSecret) {
List<Integer> validCombs = new ArrayList<Integer>(getCombTypeCount());
for (int i = 0; i < combs.length; i++) {
if (!combs[i].isSecret || includeSecret)
validCombs.add(i);
}
if (validCombs.isEmpty())
return 0;
else
return validCombs.get(random.nextInt(validCombs.size()));
}
public static ItemStack getRandomComb(int qty, Random random, boolean includeSecret) {
return ForestryItem.beeComb.getItemStack(qty, ((ItemHoneycomb) ForestryItem.beeComb.item()).getRandomCombType(random, includeSecret));
}
}
+229
View File
@@ -0,0 +1,229 @@
/*******************************************************************************
* 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.items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import forestry.api.apiculture.IAlleleBeeSpecies;
import forestry.api.apiculture.IBee;
import forestry.api.core.ForestryAPI;
import forestry.api.core.Tabs;
import forestry.apiculture.genetics.Bee;
import forestry.core.items.ItemForestry;
import forestry.core.network.GuiId;
import forestry.core.proxy.Proxies;
import forestry.plugins.PluginApiculture;
public class ItemImprinter extends ItemForestry {
public static class ImprinterInventory implements IInventory {
private final ItemStack[] inventoryStacks = new ItemStack[2];
private final short specimenSlot = 0;
private final short imprintedSlot = 1;
private int primaryIndex = 0;
private int secondaryIndex = 0;
EntityPlayer player;
public ImprinterInventory(EntityPlayer player) {
this.player = player;
}
public void advancePrimary() {
if (primaryIndex < PluginApiculture.beeInterface.getIndividualTemplates().size() - 1)
primaryIndex++;
else
primaryIndex = 0;
}
public void advanceSecondary() {
if (secondaryIndex < PluginApiculture.beeInterface.getIndividualTemplates().size() - 1)
secondaryIndex++;
else
secondaryIndex = 0;
}
public void regressPrimary() {
if (primaryIndex > 0)
primaryIndex--;
else
primaryIndex = PluginApiculture.beeInterface.getIndividualTemplates().size() - 1;
}
public void regressSecondary() {
if (secondaryIndex > 0)
secondaryIndex--;
else
secondaryIndex = PluginApiculture.beeInterface.getIndividualTemplates().size() - 1;
}
public IAlleleBeeSpecies getPrimary() {
return PluginApiculture.beeInterface.getIndividualTemplates().get(primaryIndex).getGenome().getPrimary();
}
public IAlleleBeeSpecies getSecondary() {
return PluginApiculture.beeInterface.getIndividualTemplates().get(secondaryIndex).getGenome().getPrimary();
}
public IBee getSelectedBee() {
return new Bee(PluginApiculture.beeInterface.templateAsGenome(
PluginApiculture.beeInterface.getGenomeTemplates().get(PluginApiculture.beeInterface.getIndividualTemplates().get(primaryIndex).getIdent()),
PluginApiculture.beeInterface.getGenomeTemplates().get(PluginApiculture.beeInterface.getIndividualTemplates().get(secondaryIndex).getIdent())));
}
public int getPrimaryIndex() {
return primaryIndex;
}
public int getSecondaryIndex() {
return secondaryIndex;
}
public void setPrimaryIndex(int index) {
primaryIndex = index;
}
public void setSecondaryIndex(int index) {
secondaryIndex = index;
}
private void tryImprint() {
if (inventoryStacks[specimenSlot] == null)
return;
// Only imprint bees
if (!PluginApiculture.beeInterface.isMember(inventoryStacks[specimenSlot]))
return;
// Needs space
if (inventoryStacks[imprintedSlot] != null)
return;
IBee imprint = getSelectedBee();
if (imprint == null)
return;
NBTTagCompound nbttagcompound = new NBTTagCompound();
imprint.writeToNBT(nbttagcompound);
inventoryStacks[specimenSlot].setTagCompound(nbttagcompound);
inventoryStacks[imprintedSlot] = inventoryStacks[specimenSlot];
inventoryStacks[specimenSlot] = null;
}
@Override
public ItemStack decrStackSize(int i, int j) {
if (inventoryStacks[i] == null)
return null;
ItemStack product;
if (inventoryStacks[i].stackSize <= j) {
product = inventoryStacks[i];
inventoryStacks[i] = null;
return product;
} else {
product = inventoryStacks[i].splitStack(j);
if (inventoryStacks[i].stackSize == 0)
inventoryStacks[i] = null;
return product;
}
}
@Override
public void markDirty() {
if (!Proxies.common.isSimulating(player.worldObj))
return;
tryImprint();
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
inventoryStacks[i] = itemstack;
}
@Override
public ItemStack getStackInSlot(int i) {
return inventoryStacks[i];
}
@Override
public int getSizeInventory() {
return inventoryStacks.length;
}
@Override
public String getInventoryName() {
return "Imprinter";
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
return true;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (inventoryStacks[slot] == null)
return null;
ItemStack toReturn = inventoryStacks[slot];
inventoryStacks[slot] = null;
return toReturn;
}
@Override
public boolean hasCustomInventoryName() {
return true;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
return true;
}
}
public ItemImprinter() {
super();
setCreativeTab(Tabs.tabApiculture);
setMaxStackSize(1);
}
@Override
public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer) {
if (Proxies.common.isSimulating(world))
entityplayer.openGui(ForestryAPI.instance, GuiId.ImprinterGUI.ordinal(), world, (int) entityplayer.posX, (int) entityplayer.posY,
(int) entityplayer.posZ);
return itemstack;
}
}
+36
View File
@@ -0,0 +1,36 @@
/*******************************************************************************
* 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.items;
import net.minecraft.item.ItemStack;
import forestry.core.interfaces.ICraftingPlan;
import forestry.core.items.ItemForestry;
public class ItemWaxCast extends ItemForestry implements ICraftingPlan {
public ItemWaxCast() {
super();
setMaxStackSize(1);
setMaxDamage(10);
setNoRepair();
}
@Override
public ItemStack planUsed(ItemStack plan, ItemStack result) {
plan.setItemDamage(plan.getItemDamage() + result.stackSize);
if (plan.getItemDamage() >= plan.getMaxDamage())
return null;
else
return plan;
}
}
Loaded 100 of 1602 files, more files were not shown because too many files have changed in this diff. Show more