mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-19 03:49:07 +00:00
Rename FlowerHelper to FlowerRoot and improve it
This commit is contained in:
1 parent
86bde197ec
commit
ff41a6e83b
12 files changed
+110
-90
No files matched your search
@@ -1,12 +1,12 @@
|
||||
package binnie.botany.api;
|
||||
|
||||
import forestry.api.genetics.ISpeciesType;
|
||||
import forestry.arboriculture.genetics.TreeRoot;
|
||||
|
||||
public enum EnumFlowerStage implements ISpeciesType {
|
||||
FLOWER("Flower"),
|
||||
SEED("Seed"),
|
||||
POLLEN("Pollen"),
|
||||
NONE("NONE");
|
||||
POLLEN("Pollen");
|
||||
|
||||
public static final EnumFlowerStage[] VALUES;
|
||||
String name;
|
||||
|
||||
@@ -3,6 +3,7 @@ package binnie.botany.api;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.genetics.ISpeciesType;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -30,10 +31,11 @@ public interface IFlowerRoot extends ISpeciesRoot {
|
||||
|
||||
@Override
|
||||
List<? extends IFlowerMutation> getMutations(boolean shuffle);
|
||||
|
||||
@Override
|
||||
EnumFlowerStage getType(ItemStack itemStack);
|
||||
|
||||
EnumFlowerStage getStageType(final ItemStack p0);
|
||||
|
||||
IFlower getFlower(final World p0, final IFlowerGenome p1);
|
||||
IFlower getFlower(final World p0, final IFlowerGenome genome);
|
||||
|
||||
void addConversion(final ItemStack p0, final IAllele[] p1);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package binnie.botany.core;
|
||||
|
||||
import binnie.botany.api.IFlowerRoot;
|
||||
import binnie.botany.genetics.FlowerHelper;
|
||||
import binnie.botany.genetics.FlowerRoot;
|
||||
|
||||
public class BotanyCore {
|
||||
public static final int CHANCE_INTERPOLLINATION = 20;
|
||||
@@ -12,6 +12,6 @@ public class BotanyCore {
|
||||
}
|
||||
|
||||
static {
|
||||
BotanyCore.speciesRoot = new FlowerHelper();
|
||||
BotanyCore.speciesRoot = new FlowerRoot();
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class FarmableFlower implements IFarmable {
|
||||
|
||||
@Override
|
||||
public boolean isGermling(final ItemStack itemstack) {
|
||||
final EnumFlowerStage stage = BotanyCore.speciesRoot.getStageType(itemstack);
|
||||
final EnumFlowerStage stage = BotanyCore.speciesRoot.getType(itemstack);
|
||||
return stage == EnumFlowerStage.FLOWER || stage == EnumFlowerStage.SEED;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,8 @@ import net.minecraft.world.World;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class Flower extends Individual implements IFlower {
|
||||
public IFlowerGenome genome;
|
||||
public IFlowerGenome mate;
|
||||
@@ -20,10 +22,37 @@ public class Flower extends Individual implements IFlower {
|
||||
boolean wilting;
|
||||
boolean flowered;
|
||||
|
||||
public Flower(final NBTTagCompound nbttagcompound) {
|
||||
this.age = 0;
|
||||
this.wilting = false;
|
||||
this.readFromNBT(nbttagcompound);
|
||||
public Flower(@Nonnull final NBTTagCompound nbt) {
|
||||
super(nbt);
|
||||
if (nbt == null) {
|
||||
this.genome = BotanyCore.getFlowerRoot().templateAsGenome(BotanyCore.getFlowerRoot().getDefaultTemplate());
|
||||
return;
|
||||
}
|
||||
if(nbt.hasKey("Age")){
|
||||
this.age = nbt.getInteger("Age");
|
||||
}else{
|
||||
this.age = 0;
|
||||
}
|
||||
if(nbt.hasKey("Wilt")){
|
||||
this.wilting = nbt.getBoolean("Wilt");
|
||||
}else{
|
||||
this.wilting = false;
|
||||
}
|
||||
if(nbt.hasKey("Flowered")){
|
||||
this.flowered = nbt.getBoolean("Flowered");
|
||||
}else{
|
||||
if (age > 0) {
|
||||
this.flowered = true;
|
||||
} else {
|
||||
this.flowered = false;
|
||||
}
|
||||
}
|
||||
if (nbt.hasKey("Genome")) {
|
||||
this.genome = new FlowerGenome(nbt.getCompoundTag("Genome"));
|
||||
}
|
||||
if (nbt.hasKey("Mate")) {
|
||||
this.mate = new FlowerGenome(nbt.getCompoundTag("Mate"));
|
||||
}
|
||||
}
|
||||
|
||||
public Flower(final IFlowerGenome genome, final int age) {
|
||||
@@ -70,25 +99,6 @@ public class Flower extends Individual implements IFlower {
|
||||
return this.getGenome().getPrimary().getUID();
|
||||
}
|
||||
|
||||
//TODO TEST
|
||||
//@Override
|
||||
public void readFromNBT(final NBTTagCompound nbttagcompound) {
|
||||
//super.readFromNBT(nbttagcompound);
|
||||
if (nbttagcompound == null) {
|
||||
this.genome = BotanyCore.getFlowerRoot().templateAsGenome(BotanyCore.getFlowerRoot().getDefaultTemplate());
|
||||
return;
|
||||
}
|
||||
this.age = nbttagcompound.getInteger("Age");
|
||||
this.wilting = nbttagcompound.getBoolean("Wilt");
|
||||
this.flowered = nbttagcompound.getBoolean("Flowered");
|
||||
if (nbttagcompound.hasKey("Genome")) {
|
||||
this.genome = new FlowerGenome(nbttagcompound.getCompoundTag("Genome"));
|
||||
}
|
||||
if (nbttagcompound.hasKey("Mate")) {
|
||||
this.mate = new FlowerGenome(nbttagcompound.getCompoundTag("Mate"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(final NBTTagCompound nbttagcompound2) {
|
||||
NBTTagCompound nbttagcompound = super.writeToNBT(nbttagcompound2);
|
||||
|
||||
+43
-32
@@ -3,7 +3,11 @@ package binnie.botany.genetics;
|
||||
import binnie.botany.Botany;
|
||||
import binnie.botany.api.*;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
import forestry.api.genetics.*;
|
||||
import forestry.arboriculture.PluginArboriculture;
|
||||
import forestry.arboriculture.genetics.TreeRoot;
|
||||
import forestry.core.genetics.SpeciesRoot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -12,7 +16,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
public class FlowerRoot extends SpeciesRoot implements IFlowerRoot {
|
||||
public static int flowerSpeciesCount;
|
||||
static final String UID = "rootFlowers";
|
||||
public static ArrayList<IFlower> flowerTemplates;
|
||||
@@ -20,7 +24,7 @@ public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
Map<ItemStack, IFlower> conversions;
|
||||
private static ArrayList<IColourMix> colourMixes;
|
||||
|
||||
public FlowerHelper() {
|
||||
public FlowerRoot() {
|
||||
this.conversions = new HashMap<>();
|
||||
}
|
||||
|
||||
@@ -31,25 +35,25 @@ public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
|
||||
@Override
|
||||
public int getSpeciesCount() {
|
||||
if (FlowerHelper.flowerSpeciesCount < 0) {
|
||||
FlowerHelper.flowerSpeciesCount = 0;
|
||||
if (FlowerRoot.flowerSpeciesCount < 0) {
|
||||
FlowerRoot.flowerSpeciesCount = 0;
|
||||
for (final Map.Entry<String, IAllele> entry : AlleleManager.alleleRegistry.getRegisteredAlleles().entrySet()) {
|
||||
if (entry.getValue() instanceof IAlleleFlowerSpecies && ((IAlleleFlowerSpecies) entry.getValue()).isCounted()) {
|
||||
++FlowerHelper.flowerSpeciesCount;
|
||||
++FlowerRoot.flowerSpeciesCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FlowerHelper.flowerSpeciesCount;
|
||||
return FlowerRoot.flowerSpeciesCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMember(final ItemStack stack) {
|
||||
return stack != null && this.getStageType(stack) != EnumFlowerStage.NONE;
|
||||
return stack != null && this.getType(stack) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMember(ItemStack stack, ISpeciesType type) {
|
||||
return this.getStageType(stack) == type;
|
||||
return this.getType(stack) == type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,6 +70,25 @@ public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
public ISpeciesType getIconType() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumFlowerStage getType(ItemStack stack) {
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Item item = stack.getItem();
|
||||
|
||||
if (Botany.flowerItem == item) {
|
||||
return EnumFlowerStage.SEED;
|
||||
} else if (Botany.pollen == item) {
|
||||
return EnumFlowerStage.POLLEN;
|
||||
} else if (Botany.seed == item) {
|
||||
return EnumFlowerStage.SEED;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getMemberStack(IIndividual flower, ISpeciesType type) {
|
||||
@@ -89,11 +112,6 @@ public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
return flowerStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumFlowerStage getStageType(final ItemStack stack) {
|
||||
return (stack == null) ? EnumFlowerStage.NONE : ((stack.getItem() == Botany.flowerItem) ? EnumFlowerStage.FLOWER : ((stack.getItem() == Botany.pollen) ? EnumFlowerStage.POLLEN : ((stack.getItem() == Botany.seed) ? EnumFlowerStage.SEED : EnumFlowerStage.NONE)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFlower getMember(final ItemStack stack) {
|
||||
if (!this.isMember(stack)) {
|
||||
@@ -129,7 +147,7 @@ public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
|
||||
@Override
|
||||
public ArrayList<IFlower> getIndividualTemplates() {
|
||||
return FlowerHelper.flowerTemplates;
|
||||
return FlowerRoot.flowerTemplates;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,7 +157,7 @@ public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
|
||||
@Override
|
||||
public void registerTemplate(final String identifier, final IAllele[] template) {
|
||||
FlowerHelper.flowerTemplates.add(new Flower(this.templateAsGenome(template), 2));
|
||||
FlowerRoot.flowerTemplates.add(new Flower(this.templateAsGenome(template), 2));
|
||||
if (!this.speciesTemplates.containsKey(identifier)) {
|
||||
this.speciesTemplates.put(identifier, template);
|
||||
}
|
||||
@@ -163,9 +181,9 @@ public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
@Override
|
||||
public ArrayList<IFlowerMutation> getMutations(final boolean shuffle) {
|
||||
if (shuffle) {
|
||||
Collections.shuffle(FlowerHelper.flowerMutations);
|
||||
Collections.shuffle(FlowerRoot.flowerMutations);
|
||||
}
|
||||
return FlowerHelper.flowerMutations;
|
||||
return FlowerRoot.flowerMutations;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,7 +197,7 @@ public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
if (AlleleManager.alleleRegistry.isBlacklisted(mutation.getAllele1().getUID())) {
|
||||
return;
|
||||
}
|
||||
FlowerHelper.flowerMutations.add((IFlowerMutation) mutation);
|
||||
FlowerRoot.flowerMutations.add((IFlowerMutation) mutation);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -232,29 +250,22 @@ public class FlowerHelper extends SpeciesRoot implements IFlowerRoot {
|
||||
|
||||
@Override
|
||||
public void registerColourMix(final IColourMix colourMix) {
|
||||
FlowerHelper.colourMixes.add(colourMix);
|
||||
FlowerRoot.colourMixes.add(colourMix);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IColourMix> getColourMixes(final boolean shuffle) {
|
||||
if (shuffle) {
|
||||
Collections.shuffle(FlowerHelper.colourMixes);
|
||||
Collections.shuffle(FlowerRoot.colourMixes);
|
||||
}
|
||||
return FlowerHelper.colourMixes;
|
||||
return FlowerRoot.colourMixes;
|
||||
}
|
||||
|
||||
static {
|
||||
FlowerHelper.flowerSpeciesCount = -1;
|
||||
FlowerHelper.flowerTemplates = new ArrayList<>();
|
||||
FlowerHelper.flowerMutations = new ArrayList<>();
|
||||
FlowerHelper.colourMixes = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
//TODO ??
|
||||
@Override
|
||||
public ISpeciesType getType(ItemStack itemstack) {
|
||||
return null;
|
||||
FlowerRoot.flowerSpeciesCount = -1;
|
||||
FlowerRoot.flowerTemplates = new ArrayList<>();
|
||||
FlowerRoot.flowerMutations = new ArrayList<>();
|
||||
FlowerRoot.colourMixes = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
@@ -327,6 +327,9 @@ public abstract class BreedingSystem implements IItemStackRepresentitive {
|
||||
}
|
||||
|
||||
public final void syncTracker(final IBreedingTracker tracker) {
|
||||
if(allActiveSpecies.isEmpty()){
|
||||
calculateArrays();
|
||||
}
|
||||
this.discoveredSpeciesPercentage = 0.0f;
|
||||
this.totalSpeciesCount = 0;
|
||||
this.discoveredSpeciesCount = 0;
|
||||
|
||||
@@ -59,7 +59,7 @@ class FlowerBreedingSystem extends BreedingSystem {
|
||||
|
||||
@Override
|
||||
public boolean isDNAManipulable(final ItemStack member) {
|
||||
return ((IFlowerRoot) this.getSpeciesRoot()).getStageType(member) == EnumFlowerStage.POLLEN;
|
||||
return ((IFlowerRoot) this.getSpeciesRoot()).getType(member) == EnumFlowerStage.POLLEN;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,8 @@ package binnie.core.item;
|
||||
import forestry.api.core.IItemModelRegister;
|
||||
import forestry.api.core.IModelManager;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemCore extends Item implements IItemModelRegister{
|
||||
|
||||
@@ -10,6 +12,7 @@ public class ItemCore extends Item implements IItemModelRegister{
|
||||
setRegistryName(registryName);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
manager.registerItemModel(item, 0);
|
||||
|
||||
@@ -32,6 +32,7 @@ import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IBreedingTracker;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.ISpeciesRoot;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
@@ -98,9 +99,12 @@ public class WindowAnalyst extends Window {
|
||||
@Override
|
||||
public void initialiseServer() {
|
||||
for (final BreedingSystem system : Binnie.Genetics.getActiveSystems()) {
|
||||
final IBreedingTracker tracker = system.getSpeciesRoot().getBreedingTracker(this.getWorld(), this.getUsername());
|
||||
if (tracker != null) {
|
||||
tracker.synchToPlayer(this.getPlayer());
|
||||
ISpeciesRoot root = system.getSpeciesRoot();
|
||||
if(root != null){
|
||||
final IBreedingTracker tracker = root.getBreedingTracker(this.getWorld(), this.getUsername());
|
||||
if (tracker != null) {
|
||||
tracker.synchToPlayer(this.getPlayer());
|
||||
}
|
||||
}
|
||||
}
|
||||
this.setupValidators();
|
||||
|
||||
@@ -19,27 +19,6 @@ import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemDatabase extends ItemCore{
|
||||
// IIcon iconMaster;
|
||||
//
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public void registerIcons(final IIconRegister register) {
|
||||
// this.itemIcon = Genetics.proxy.getIcon(register, "geneDatabase");
|
||||
// this.iconMaster = Genetics.proxy.getIcon(register, "masterGeneDatabase");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @SideOnly(Side.CLIENT)
|
||||
// public IIcon getIconFromDamage(final int par1) {
|
||||
// return (par1 == 0) ? this.itemIcon : this.iconMaster;
|
||||
// }
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems) {
|
||||
super.getSubItems(itemIn, tab, subItems);
|
||||
subItems.add(new ItemStack(itemIn, 1, 1));
|
||||
}
|
||||
|
||||
public ItemDatabase() {
|
||||
super("geneticdatabase");
|
||||
@@ -48,10 +27,18 @@ public class ItemDatabase extends ItemCore{
|
||||
this.setMaxStackSize(1);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerModel(Item item, IModelManager manager) {
|
||||
manager.registerItemModel(item, 0);
|
||||
manager.registerItemModel(item, 1, "master");
|
||||
manager.registerItemModel(item, 1, "geneticdatabase_master");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getSubItems(Item itemIn, CreativeTabs tab, List<ItemStack> subItems) {
|
||||
super.getSubItems(itemIn, tab, subItems);
|
||||
subItems.add(new ItemStack(itemIn, 1, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user