mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 01:04:12 +00:00
Fix #791 *alyzer slot behavior changed. (can't swap specimens)
This commit is contained in:
1 parent
5052df8844
commit
1d0efd537e
5 files changed
+90
-125
No files matched your search
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in new issue
Block a user