Search in sources :

Example 1 with EnumBeeChromosome

use of forestry.api.apiculture.EnumBeeChromosome in project Railcraft by Railcraft.

the class ItemFilterBeeGenome method getBeeFilter.

@Nullable
public static BeeFilter getBeeFilter(ItemStack stack) {
    NBTTagCompound nbt = InvTools.getItemDataRailcraft(stack, "filter");
    if (nbt != null) {
        try {
            String typeName = nbt.getString("type");
            EnumBeeType type = null;
            try {
                type = EnumBeeType.valueOf(typeName);
            } catch (IllegalArgumentException ignored) {
            }
            EnumBeeChromosome chromosome = EnumBeeChromosome.SPECIES;
            try {
                chromosome = EnumBeeChromosome.valueOf(nbt.getString("chromosome"));
            } catch (IllegalArgumentException ignored) {
            }
            ItemStack active = NBTPlugin.readItemStack(nbt, "active");
            ItemStack inactive = NBTPlugin.readItemStack(nbt, "inactive");
            return new BeeFilter(type, chromosome, active, inactive);
        } catch (Throwable ignored) {
        }
    }
    return new BeeFilter(null, EnumBeeChromosome.SPECIES, null, null);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EnumBeeType(forestry.api.apiculture.EnumBeeType) EnumBeeChromosome(forestry.api.apiculture.EnumBeeChromosome) Nullable(javax.annotation.Nullable)

Example 2 with EnumBeeChromosome

use of forestry.api.apiculture.EnumBeeChromosome in project Railcraft by Railcraft.

the class ItemFilterBeeGenome method onItemRightClick.

@Optional.Method(modid = ForestryPlugin.FORESTRY_ID)
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand) {
    NBTTagCompound nbt = InvTools.getItemDataRailcraft(stack, "filter");
    if (nbt != null) {
        try {
            EnumBeeChromosome chromosome = EnumBeeChromosome.SPECIES;
            try {
                chromosome = EnumBeeChromosome.valueOf(nbt.getString("chromosome"));
            } catch (IllegalArgumentException ignored) {
            }
            chromosome = EnumTools.next(chromosome, EnumBeeChromosome.values());
            nbt.setString("chromosome", chromosome.name());
        } catch (Throwable throwable) {
            Game.logErrorAPI(Mod.FORESTRY.modId, throwable, EnumBeeChromosome.class);
        }
    }
    return new ActionResult<>(EnumActionResult.SUCCESS, stack.copy());
}
Also used : ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EnumBeeChromosome(forestry.api.apiculture.EnumBeeChromosome)

Aggregations

EnumBeeChromosome (forestry.api.apiculture.EnumBeeChromosome)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 EnumBeeType (forestry.api.apiculture.EnumBeeType)1 Nullable (javax.annotation.Nullable)1 ItemStack (net.minecraft.item.ItemStack)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1