Compare commits

..
5 Commits
15 changed files with 139 additions and 183 deletions

No files matched your search

+1 -1
View File
@@ -2,4 +2,4 @@ mcversion=1.7.10
forgeversion=10.13.3.1370-1.7.10
version_major=4
version_minor=0
version_patch=2
version_patch=3
@@ -12,13 +12,12 @@ package forestry.apiculture.items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import forestry.api.apiculture.BeeManager;
import forestry.api.apiculture.IBee;
import forestry.api.core.ForestryAPI;
import forestry.api.core.Tabs;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.config.Config;
import forestry.core.gui.IHintSource;
import forestry.core.items.ItemAlyzer;
@@ -48,48 +47,11 @@ public class ItemBeealyzer extends ItemAlyzer {
}
@Override
protected boolean isSpecimen(ItemStack itemStack) {
return BeeManager.beeRoot.isMember(itemStack);
protected ISpeciesRoot getSpeciesRoot() {
return BeeManager.beeRoot;
}
@Override
public void onSlotClick(EntityPlayer player) {
// Source slot to analyze empty
if (getStackInSlot(SLOT_SPECIMEN) == null) {
return;
}
IBee bee = BeeManager.beeRoot.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) {
BeeManager.beeRoot.getBreedingTracker(player.worldObj, player.getGameProfile()).registerSpecies(bee.getGenome().getPrimary());
BeeManager.beeRoot.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);
}
// / IHINTSOURCE
@Override
@@ -12,13 +12,12 @@ package forestry.arboriculture.items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import forestry.api.arboriculture.ITree;
import forestry.api.arboriculture.TreeManager;
import forestry.api.core.ForestryAPI;
import forestry.api.core.Tabs;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.config.Config;
import forestry.core.gui.IHintSource;
import forestry.core.items.ItemAlyzer;
@@ -50,52 +49,32 @@ public class ItemTreealyzer extends ItemAlyzer {
}
@Override
protected boolean isSpecimen(ItemStack itemStack) {
return GeneticsUtil.getGeneticEquivalent(itemStack) instanceof ITree;
protected ISpeciesRoot getSpeciesRoot() {
return TreeManager.treeRoot;
}
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (!TreeManager.treeRoot.isMember(itemStack)) {
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(itemStack);
if (ersatz != null) {
return super.canSlotAccept(slotIndex, ersatz);
}
}
return super.canSlotAccept(slotIndex, itemStack);
}
@Override
public void onSlotClick(EntityPlayer player) {
// Source slot to analyze empty
if (getStackInSlot(SLOT_SPECIMEN) == null) {
return;
}
if (!TreeManager.treeRoot.isMember(getStackInSlot(SLOT_SPECIMEN))) {
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(getStackInSlot(SLOT_SPECIMEN));
ItemStack specimen = getStackInSlot(SLOT_SPECIMEN);
if (!TreeManager.treeRoot.isMember(specimen)) {
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(specimen);
if (ersatz != null) {
setInventorySlotContents(SLOT_SPECIMEN, ersatz);
}
}
ITree tree = TreeManager.treeRoot.getMember(getStackInSlot(SLOT_SPECIMEN));
// No tree, abort
if (tree == null) {
return;
}
// Analyze if necessary
if (!tree.isAnalyzed()) {
// Requires energy
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
return;
}
tree.analyze();
if (player != null) {
TreeManager.treeRoot.getBreedingTracker(player.worldObj, player.getGameProfile()).registerSpecies(tree.getGenome().getPrimary());
TreeManager.treeRoot.getBreedingTracker(player.worldObj, player.getGameProfile()).registerSpecies(tree.getGenome().getSecondary());
}
NBTTagCompound nbttagcompound = new NBTTagCompound();
tree.writeToNBT(nbttagcompound);
getStackInSlot(SLOT_SPECIMEN).setTagCompound(nbttagcompound);
// Decrease energy
decrStackSize(SLOT_ENERGY, 1);
}
setInventorySlotContents(SLOT_ANALYZE_1, getStackInSlot(SLOT_SPECIMEN));
setInventorySlotContents(SLOT_SPECIMEN, null);
super.onSlotClick(player);
}
// / IHINTSOURCE
@@ -21,7 +21,6 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
@@ -196,23 +195,6 @@ public final class FluidHelper {
return output.stackSize + drainedItem.stackSize <= output.getMaxStackSize();
}
public static boolean isFillableContainer(ItemStack stack, FluidStack liquid) {
ItemStack empty = ItemStackUtil.createSplitStack(stack, 1);
Item item = empty.getItem();
if (item instanceof IFluidContainerItem) {
IFluidContainerItem containerItem = (IFluidContainerItem) item;
return containerItem.fill(empty, liquid, false) > 0;
}
for (FluidContainerData cont : FluidContainerRegistry.getRegisteredFluidContainerData()) {
if (cont.fluid.isFluidEqual(liquid) && (cont.emptyContainer != null && cont.emptyContainer.isItemEqual(empty))) {
return true;
}
}
return false;
}
public static boolean isEmptyContainer(ItemStack empty) {
if (FluidContainerRegistry.isEmptyContainer(empty)) {
@@ -299,8 +281,7 @@ public final class FluidHelper {
Item item = empty.getItem();
if (item instanceof IFluidContainerItem) {
ItemStack full = empty.copy();
full.stackSize = 1;
ItemStack full = ItemStackUtil.createSplitStack(empty, 1);
IFluidContainerItem containerItem = (IFluidContainerItem) item;
containerItem.fill(full, liquid, true);
return full;
@@ -142,8 +142,8 @@ public class ItemResearchNote extends ItemForestry {
return false;
}
IAlleleSpecies species0 = (IAlleleSpecies) encoded.getAllele0();
IAlleleSpecies species1 = (IAlleleSpecies) encoded.getAllele1();
IAlleleSpecies species0 = encoded.getAllele0();
IAlleleSpecies species1 = encoded.getAllele1();
IAlleleSpecies speciesResult = (IAlleleSpecies) encoded.getTemplate()[root.getKaryotypeKey().ordinal()];
tracker.registerSpecies(species0);
@@ -139,16 +139,6 @@ public abstract class Mutation implements IMutationCustom {
return species1;
}
@Override
public IAlleleSpecies getSpecies0() {
return species0;
}
@Override
public IAlleleSpecies getSpecies1() {
return species1;
}
@Override
public float getBaseChance() {
return chance;
@@ -14,9 +14,13 @@ import com.google.common.collect.ImmutableSet;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import forestry.api.core.IErrorSource;
import forestry.api.core.IErrorState;
import forestry.api.genetics.IBreedingTracker;
import forestry.api.genetics.IIndividual;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.config.ForestryItem;
import forestry.core.errors.EnumErrorCode;
import forestry.core.inventory.ItemInventory;
@@ -58,15 +62,71 @@ public abstract class ItemAlyzer extends ItemInventoried {
return false;
}
protected abstract boolean isSpecimen(ItemStack itemStack);
protected abstract ISpeciesRoot getSpeciesRoot();
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (slotIndex == SLOT_ENERGY) {
return isEnergy(itemStack);
} else {
return !hasSpecimen() && isSpecimen(itemStack);
}
ISpeciesRoot speciesRoot = getSpeciesRoot();
if (!speciesRoot.isMember(itemStack)) {
return false;
}
// only allow one slot to be used at a time
if (hasSpecimen() && getStackInSlot(slotIndex) == null) {
return false;
}
if (slotIndex == SLOT_SPECIMEN) {
return true;
}
IIndividual individual = speciesRoot.getMember(itemStack);
return individual.isAnalyzed();
}
@Override
public void onSlotClick(EntityPlayer player) {
// Source slot to analyze empty
ItemStack specimen = getStackInSlot(SLOT_SPECIMEN);
if (specimen == null) {
return;
}
IIndividual individual = getSpeciesRoot().getMember(specimen);
// No individual, abort
if (individual == null) {
return;
}
// Analyze if necessary
if (!individual.isAnalyzed()) {
// Requires energy
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
return;
}
individual.analyze();
if (player != null) {
IBreedingTracker breedingTracker = getSpeciesRoot().getBreedingTracker(player.worldObj, player.getGameProfile());
breedingTracker.registerSpecies(individual.getGenome().getPrimary());
breedingTracker.registerSpecies(individual.getGenome().getSecondary());
}
NBTTagCompound nbttagcompound = new NBTTagCompound();
individual.writeToNBT(nbttagcompound);
specimen.setTagCompound(nbttagcompound);
// Decrease energy
decrStackSize(SLOT_ENERGY, 1);
}
setInventorySlotContents(SLOT_ANALYZE_1, specimen);
setInventorySlotContents(SLOT_SPECIMEN, null);
}
@Override
@@ -159,6 +159,9 @@ public class GeneticsUtil {
}
public static IIndividual getGeneticEquivalent(ItemStack itemStack) {
if (itemStack == null) {
return null;
}
Item item = itemStack.getItem();
if (item instanceof ItemGE) {
return ((ItemGE) item).getIndividual(itemStack);
@@ -192,16 +195,14 @@ public class GeneticsUtil {
exclude.add(species);
for (IMutation mutation : species.getRoot().getPaths(species, speciesChromosome)) {
IAlleleSpecies species0 = (IAlleleSpecies) mutation.getAllele0();
IAlleleSpecies species1 = (IAlleleSpecies) mutation.getAllele1();
if (!exclude.contains(species0)) {
int otherAdvance = getGeneticAdvancement(species0, exclude, speciesChromosome);
if (!exclude.contains(mutation.getAllele0())) {
int otherAdvance = getGeneticAdvancement(mutation.getAllele0(), exclude, speciesChromosome);
if (otherAdvance > highest) {
highest = otherAdvance;
}
}
if (!exclude.contains(species1)) {
int otherAdvance = getGeneticAdvancement(species1, exclude, speciesChromosome);
if (!exclude.contains(mutation.getAllele1())) {
int otherAdvance = getGeneticAdvancement(mutation.getAllele1(), exclude, speciesChromosome);
if (otherAdvance > highest) {
highest = otherAdvance;
}
@@ -202,7 +202,7 @@ public abstract class ItemStackUtil {
return false;
}
if (craftingTools && isCraftingTool(base) && base.getItem() == comparison.getItem()) {
if (craftingTools && isCraftingToolEquivalent(base, comparison)) {
return true;
}
@@ -235,19 +235,30 @@ public abstract class ItemStackUtil {
return false;
}
public static boolean isCraftingTool(ItemStack itemstack) {
Item item = itemstack.getItem();
if (item == null) {
public static boolean isCraftingToolEquivalent(ItemStack base, ItemStack comparison) {
if (base == null || comparison == null) {
return false;
}
if (item.hasContainerItem(itemstack)) {
if (item.isDamageable() || itemstack.hasTagCompound()) {
return !item.doesContainerItemLeaveCraftingGrid(itemstack);
}
Item baseItem = base.getItem();
if (baseItem.doesContainerItemLeaveCraftingGrid(base)) {
return false;
}
return false;
if (baseItem != comparison.getItem()) {
return false;
}
if (base.stackTagCompound == null || base.stackTagCompound.hasNoTags()) {
// tool uses meta for damage
return true;
} else {
// tool uses NBT for damage
if (base.getItemDamage() == OreDictionary.WILDCARD_VALUE) {
return true;
}
return base.getItemDamage() == comparison.getItemDamage();
}
}
public static void dropItemStackAsEntity(ItemStack items, World world, double x, double y, double z) {
@@ -15,6 +15,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import forestry.core.fluids.FluidHelper;
import forestry.core.utils.ItemStackUtil;
public class SqueezerContainerRecipe implements ISqueezerContainerRecipe {
@@ -52,9 +53,14 @@ public class SqueezerContainerRecipe implements ISqueezerContainerRecipe {
@Override
public ISqueezerRecipe getSqueezerRecipe(ItemStack filledContainer) {
if (filledContainer == null) {
return null;
}
FluidStack fluidOutput = FluidHelper.getFluidStackInContainer(filledContainer);
ItemStack filledContainerCopy = filledContainer.copy();
filledContainerCopy.stackSize = 1;
if (fluidOutput == null) {
return null;
}
ItemStack filledContainerCopy = ItemStackUtil.createSplitStack(filledContainer, 1);
return new SqueezerRecipe(processingTime, new ItemStack[]{filledContainerCopy}, fluidOutput, remnants, remnantsChance);
}
@@ -221,10 +221,12 @@ public class NEIHandlerSqueezer extends RecipeHandlerBase {
}
for (ISqueezerContainerRecipe containerRecipe : TileSqueezer.RecipeManager.containerRecipes.values()) {
ItemStack emptyContainer = containerRecipe.getEmptyContainer();
if (FluidHelper.isFillableContainer(emptyContainer, result)) {
ItemStack filledContainer = FluidHelper.getFilledContainer(result, emptyContainer);
ItemStack filledContainer = FluidHelper.getFilledContainer(result, emptyContainer);
if (filledContainer != null) {
ISqueezerRecipe recipe = containerRecipe.getSqueezerRecipe(filledContainer);
this.arecipes.add(new CachedSqueezerRecipe(recipe, true));
if (recipe != null) {
this.arecipes.add(new CachedSqueezerRecipe(recipe, true));
}
}
}
}
@@ -230,7 +230,7 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa
@Override
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
if (slotIndex == SLOT_RESOURCE) {
return FluidHelper.isFillableContainer(itemStack, Fluids.WATER.getFluid(1000));
return FluidHelper.getFilledContainer(Fluids.WATER.getFluid(1000), itemStack) != null;
}
return false;
}
@@ -415,9 +415,12 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
public static ISqueezerRecipe findMatchingRecipe(ItemStack[] items) {
// Find container recipes
for (ItemStack itemStack : items) {
ISqueezerContainerRecipe recipe = findMatchingContainerRecipe(itemStack);
if (recipe != null) {
return recipe.getSqueezerRecipe(itemStack);
ISqueezerContainerRecipe containerRecipe = findMatchingContainerRecipe(itemStack);
if (containerRecipe != null) {
ISqueezerRecipe recipe = containerRecipe.getSqueezerRecipe(itemStack);
if (recipe != null) {
return recipe;
}
}
}
@@ -12,12 +12,11 @@ package forestry.lepidopterology.items;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import forestry.api.core.ForestryAPI;
import forestry.api.core.Tabs;
import forestry.api.lepidopterology.IButterfly;
import forestry.api.genetics.ISpeciesRoot;
import forestry.core.config.Config;
import forestry.core.gui.IHintSource;
import forestry.core.items.ItemAlyzer;
@@ -33,46 +32,8 @@ public class ItemFlutterlyzer extends ItemAlyzer {
}
@Override
protected boolean isSpecimen(ItemStack itemStack) {
return PluginLepidopterology.butterflyInterface.isMember(itemStack);
}
@Override
public void onSlotClick(EntityPlayer player) {
// Source slot to analyze empty
if (getStackInSlot(SLOT_SPECIMEN) == null) {
return;
}
IButterfly butterfly = PluginLepidopterology.butterflyInterface.getMember(getStackInSlot(SLOT_SPECIMEN));
// No tree, abort
if (butterfly == null) {
return;
}
// Analyze if necessary
if (!butterfly.isAnalyzed()) {
// Requires energy
if (!isEnergy(getStackInSlot(SLOT_ENERGY))) {
return;
}
butterfly.analyze();
if (player != null) {
PluginLepidopterology.butterflyInterface.getBreedingTracker(player.worldObj, player.getGameProfile()).registerSpecies(butterfly.getGenome().getPrimary());
PluginLepidopterology.butterflyInterface.getBreedingTracker(player.worldObj, player.getGameProfile()).registerSpecies(butterfly.getGenome().getSecondary());
}
NBTTagCompound nbttagcompound = new NBTTagCompound();
butterfly.writeToNBT(nbttagcompound);
getStackInSlot(SLOT_SPECIMEN).setTagCompound(nbttagcompound);
// Decrease energy
decrStackSize(SLOT_ENERGY, 1);
}
setInventorySlotContents(SLOT_ANALYZE_1, getStackInSlot(SLOT_SPECIMEN));
setInventorySlotContents(SLOT_SPECIMEN, null);
protected ISpeciesRoot getSpeciesRoot() {
return PluginLepidopterology.butterflyInterface;
}
/* IHINTSOURCE */