mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 11:49:14 +00:00
Clean up pollination. Add pollination for vanilla Acacia and Dark Oak
This commit is contained in:
1 parent
db0ab5feda
commit
90f80da4da
11 files changed
+209
-163
No files matched your search
@@ -31,21 +31,22 @@ import forestry.api.genetics.IFlowerProvider;
|
||||
import forestry.api.genetics.IGenome;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
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;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -604,39 +605,26 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
if (area.z < 1)
|
||||
area.z = 1;
|
||||
|
||||
// We have up to ten attempts
|
||||
World world = housing.getWorld();
|
||||
Random random = world.rand;
|
||||
|
||||
Vect housingPos = new Vect(housing.getXCoord(), housing.getYCoord(), housing.getZCoord());
|
||||
|
||||
IIndividual pollen = null;
|
||||
|
||||
for (int i = 0; i < 20; i++) {
|
||||
Vect randomPos = new Vect(random.nextInt(area.x), random.nextInt(area.y), random.nextInt(area.z));
|
||||
Vect blockPos = housingPos.add(randomPos).add(offset);
|
||||
TileEntity tile = world.getTileEntity(blockPos.x, blockPos.y, blockPos.z);
|
||||
|
||||
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;
|
||||
if (tile instanceof IPollinatable) {
|
||||
IPollinatable pitcher = (IPollinatable) tile;
|
||||
if (genome.getFlowerProvider().isAcceptedPollinatable(world, pitcher))
|
||||
pollen = pitcher.getPollen();
|
||||
} else {
|
||||
pollen = GeneticsUtil.getErsatzPollen(world, blockPos.x, blockPos.y, blockPos.z);
|
||||
}
|
||||
|
||||
IPollinatable pitcher = (IPollinatable) tile;
|
||||
if (!genome.getFlowerProvider().isAcceptedPollinatable(housing.getWorld(), pitcher))
|
||||
continue;
|
||||
|
||||
IIndividual pollen = pitcher.getPollen();
|
||||
|
||||
if (pollen != null)
|
||||
return pollen;
|
||||
}
|
||||
@@ -664,7 +652,6 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
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));
|
||||
@@ -672,7 +659,7 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
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);
|
||||
IPollinatable receiver = GeneticsUtil.getOrCreatePollinatable(housing.getOwnerName(), housing.getWorld(), posBlock.x, posBlock.y, posBlock.z);
|
||||
if(receiver == null)
|
||||
continue;
|
||||
|
||||
|
||||
@@ -10,9 +10,27 @@
|
||||
******************************************************************************/
|
||||
package forestry.arboriculture.gadgets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.arboriculture.IAlleleFruit;
|
||||
import forestry.api.arboriculture.IFruitProvider;
|
||||
import forestry.api.arboriculture.ILeafTickHandler;
|
||||
@@ -30,6 +48,7 @@ import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.api.lepidopterology.IButterflyRoot;
|
||||
import forestry.arboriculture.network.PacketLeafUpdate;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.genetics.Allele;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
@@ -37,19 +56,6 @@ import forestry.core.proxy.Proxies;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraftforge.common.EnumPlantType;
|
||||
|
||||
public class TileLeaves extends TileTreeContainer implements IPollinatable, IFruitBearer, IButterflyNursery {
|
||||
|
||||
@@ -175,7 +181,7 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
|
||||
}
|
||||
|
||||
public int getFoliageColour(EntityPlayer player) {
|
||||
return isPollinatedState & Utils.hasNaturalistEye(player) ? 0xffffff : colourLeaves;
|
||||
return isPollinatedState & GeneticsUtil.hasNaturalistEye(player) ? 0xffffff : colourLeaves;
|
||||
}
|
||||
|
||||
public int getFruitColour() {
|
||||
|
||||
@@ -10,9 +10,15 @@
|
||||
******************************************************************************/
|
||||
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.core.ForestryAPI;
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.ForestryItem;
|
||||
@@ -22,12 +28,7 @@ import forestry.core.inventory.AlyzerInventory;
|
||||
import forestry.core.items.ItemInventoried;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemTreealyzer extends ItemInventoried {
|
||||
|
||||
@@ -62,7 +63,7 @@ public class ItemTreealyzer extends ItemInventoried {
|
||||
return;
|
||||
|
||||
if (!PluginArboriculture.treeInterface.isMember(getStackInSlot(SLOT_SPECIMEN))) {
|
||||
ItemStack ersatz = Utils.convertSaplingToGeneticEquivalent(getStackInSlot(SLOT_SPECIMEN));
|
||||
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(getStackInSlot(SLOT_SPECIMEN));
|
||||
if (ersatz != null)
|
||||
setInventorySlotContents(SLOT_SPECIMEN, ersatz);
|
||||
}
|
||||
|
||||
@@ -20,10 +20,10 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;
|
||||
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Version;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Utils;
|
||||
|
||||
public class TickHandlerCoreClient {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class TickHandlerCoreClient {
|
||||
if (event.phase != Phase.END) return;
|
||||
|
||||
EntityPlayer player = Proxies.common.getClientInstance().thePlayer;
|
||||
boolean hasNaturalistEye = Utils.hasNaturalistEye(player);
|
||||
boolean hasNaturalistEye = GeneticsUtil.hasNaturalistEye(player);
|
||||
if (hasNaturalistEye != hasNaturalistView) {
|
||||
hasNaturalistView = !hasNaturalistView;
|
||||
Proxies.common.getClientInstance().renderGlobal.markBlockRangeForRenderUpdate(
|
||||
|
||||
@@ -10,10 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
import forestry.core.interfaces.ICrafter;
|
||||
import forestry.core.interfaces.IRenderableMachine;
|
||||
import forestry.core.inventory.TileInventoryAdapter;
|
||||
@@ -24,11 +31,6 @@ import forestry.core.network.PacketTileNBT;
|
||||
import forestry.core.network.PacketTileUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.utils.Utils;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class TileEscritoire extends TileBase implements ISidedInventory, IRenderableMachine, ICrafter {
|
||||
|
||||
@@ -151,7 +153,7 @@ public class TileEscritoire extends TileBase implements ISidedInventory, IRender
|
||||
if (slotIndex == SLOT_ANALYZE && Proxies.common.isSimulating(worldObj)) {
|
||||
if (!AlleleManager.alleleRegistry.isIndividual(inventory.getStackInSlot(SLOT_ANALYZE))
|
||||
&& inventory.getStackInSlot(SLOT_ANALYZE) != null) {
|
||||
ItemStack ersatz = Utils.convertSaplingToGeneticEquivalent(inventory.getStackInSlot(SLOT_ANALYZE));
|
||||
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(inventory.getStackInSlot(SLOT_ANALYZE));
|
||||
if (ersatz != null)
|
||||
inventory.setInventorySlotContents(SLOT_ANALYZE, ersatz);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/*******************************************************************************
|
||||
* 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.core.utils;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.core.IArmorNaturalist;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
|
||||
public class GeneticsUtil {
|
||||
|
||||
private static Set<Material> ersatzSpecimenMaterials;
|
||||
|
||||
private static Set<Material> getErsatzSpecimenMaterials() {
|
||||
if (ersatzSpecimenMaterials == null) {
|
||||
ersatzSpecimenMaterials = new HashSet<Material>();
|
||||
for (ItemStack ersatzSpecimen : AlleleManager.ersatzSpecimen.keySet()) {
|
||||
Block ersatzBlock = StackUtils.getBlock(ersatzSpecimen);
|
||||
if (ersatzBlock != null)
|
||||
ersatzSpecimenMaterials.add(ersatzBlock.getMaterial());
|
||||
}
|
||||
}
|
||||
return ersatzSpecimenMaterials;
|
||||
}
|
||||
|
||||
private static boolean isErsatzMaterial(Block block) {
|
||||
return block != null && getErsatzSpecimenMaterials().contains(block.getMaterial());
|
||||
}
|
||||
|
||||
public static boolean hasNaturalistEye(EntityPlayer player) {
|
||||
ItemStack armorItem = player.inventory.armorInventory[3];
|
||||
return armorItem != null && armorItem.getItem() instanceof IArmorNaturalist
|
||||
&& ((IArmorNaturalist) armorItem.getItem()).canSeePollination(player, armorItem, true);
|
||||
}
|
||||
|
||||
public static IPollinatable getOrCreatePollinatable(GameProfile owner, World world, final int x, final int y, final int z) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof IPollinatable) {
|
||||
return (IPollinatable) tile;
|
||||
}
|
||||
|
||||
IIndividual pollen = getErsatzPollen(world, x, y, z);
|
||||
if (pollen != null) {
|
||||
PluginArboriculture.treeInterface.setLeaves(world, pollen, owner, x, y, z);
|
||||
return (IPollinatable) world.getTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static IIndividual getErsatzPollen(World world, final int x, final int y, final int z) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
if (!isErsatzMaterial(block))
|
||||
return null;
|
||||
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if (Blocks.leaves == block || Blocks.leaves2 == block) {
|
||||
if ((meta & 4) != 0) {
|
||||
// no-decay vanilla leaves. http://minecraft.gamepedia.com/Data_values#Leaves
|
||||
// Treat them as decorative and don't pollinate.
|
||||
return null;
|
||||
}
|
||||
meta %= 3;
|
||||
}
|
||||
|
||||
// Find the matching ersatz genome
|
||||
for (ItemStack ersatzSpecimen : AlleleManager.ersatzSpecimen.keySet()) {
|
||||
if (StackUtils.equals(block, meta, ersatzSpecimen)) {
|
||||
return AlleleManager.ersatzSpecimen.get(ersatzSpecimen).copy();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack convertSaplingToGeneticEquivalent(ItemStack foreign) {
|
||||
|
||||
ItemStack ersatz = null;
|
||||
ITree tree = null;
|
||||
|
||||
for (Map.Entry<ItemStack, IIndividual> entry : AlleleManager.ersatzSaplings.entrySet()) {
|
||||
if (entry.getKey().getItem() != foreign.getItem())
|
||||
continue;
|
||||
if (entry.getKey().getItemDamage() != foreign.getItemDamage())
|
||||
continue;
|
||||
|
||||
if (entry.getValue() instanceof ITree)
|
||||
tree = (ITree) entry.getValue();
|
||||
|
||||
ersatz = PluginArboriculture.treeInterface.getMemberStack(tree, EnumGermlingType.SAPLING.ordinal());
|
||||
ersatz.stackSize = foreign.stackSize;
|
||||
}
|
||||
|
||||
return ersatz;
|
||||
}
|
||||
}
|
||||
@@ -425,4 +425,8 @@ public class StackUtils {
|
||||
public static boolean equals(Block block, ItemStack stack) {
|
||||
return block == getBlock(stack);
|
||||
}
|
||||
|
||||
public static boolean equals(Block block, int meta, ItemStack stack) {
|
||||
return block == getBlock(stack) && meta == stack.getItemDamage();
|
||||
}
|
||||
}
|
||||
@@ -10,25 +10,11 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.utils;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
import forestry.api.arboriculture.EnumGermlingType;
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IArmorNaturalist;
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityList;
|
||||
@@ -45,6 +31,15 @@ import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static Random rand;
|
||||
@@ -115,12 +110,6 @@ public class Utils {
|
||||
|
||||
}
|
||||
|
||||
public static boolean hasNaturalistEye(EntityPlayer player) {
|
||||
ItemStack armorItem = player.inventory.armorInventory[3];
|
||||
return armorItem != null && armorItem.getItem() instanceof IArmorNaturalist
|
||||
&& ((IArmorNaturalist) armorItem.getItem()).canSeePollination(player, armorItem, true);
|
||||
}
|
||||
|
||||
public static IInventory getChest(IInventory inventory) {
|
||||
if (!(inventory instanceof TileEntityChest))
|
||||
return inventory;
|
||||
@@ -320,60 +309,4 @@ public class Utils {
|
||||
}
|
||||
return hex.toString();
|
||||
}
|
||||
|
||||
public static ItemStack convertSaplingToGeneticEquivalent(ItemStack foreign) {
|
||||
|
||||
ItemStack ersatz = null;
|
||||
ITree tree = null;
|
||||
|
||||
for (Map.Entry<ItemStack, IIndividual> entry : AlleleManager.ersatzSaplings.entrySet()) {
|
||||
if (entry.getKey().getItem() != foreign.getItem())
|
||||
continue;
|
||||
if (entry.getKey().getItemDamage() != foreign.getItemDamage())
|
||||
continue;
|
||||
|
||||
if (entry.getValue() instanceof ITree)
|
||||
tree = (ITree) entry.getValue();
|
||||
|
||||
ersatz = PluginArboriculture.treeInterface.getMemberStack(tree, EnumGermlingType.SAPLING.ordinal());
|
||||
ersatz.stackSize = foreign.stackSize;
|
||||
}
|
||||
|
||||
return ersatz;
|
||||
}
|
||||
|
||||
public static IPollinatable getOrCreatePollinatable(GameProfile owner, World world, final int x, final int y, final int z) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
IPollinatable receiver = null;
|
||||
if (tile instanceof IPollinatable)
|
||||
receiver = (IPollinatable) tile;
|
||||
else if (!world.isAirBlock(x, y, z)) {
|
||||
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
if (Blocks.leaves == block || Blocks.leaves2 == block) {
|
||||
if ((meta & 4) != 0) {
|
||||
// no-decay vanilla leaves. http://minecraft.gamepedia.com/Data_values#Leaves
|
||||
// Treat them as decorative and don't pollinate.
|
||||
return null;
|
||||
}
|
||||
meta = meta % 3;
|
||||
}
|
||||
|
||||
// Test for ersatz genomes
|
||||
for (Map.Entry<ItemStack, IIndividual> entry : AlleleManager.ersatzSpecimen.entrySet()) {
|
||||
if (block == StackUtils.getBlock(entry.getKey()) && entry.getKey().getItemDamage() == meta) {
|
||||
// We matched, replace the leaf block with ours and set the ersatz genome
|
||||
PluginArboriculture.treeInterface.setLeaves(world, entry.getValue(), owner, x, y, z);
|
||||
// Now let's pollinate
|
||||
receiver = (IPollinatable) world.getTileEntity(x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return receiver;
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,10 @@
|
||||
******************************************************************************/
|
||||
package forestry.lepidopterology.entities;
|
||||
|
||||
import forestry.api.arboriculture.ITreeRoot;
|
||||
import forestry.api.genetics.AlleleManager;
|
||||
import forestry.api.genetics.IIndividual;
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import java.util.Map;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class AIButterflyMate extends AIButterflyInteract {
|
||||
@@ -43,23 +39,13 @@ public class AIButterflyMate extends AIButterflyInteract {
|
||||
|
||||
if (tile instanceof IButterflyNursery)
|
||||
nursery = (IButterflyNursery) tile;
|
||||
else
|
||||
for (Map.Entry<ItemStack, IIndividual> entry : AlleleManager.ersatzSpecimen.entrySet()) {
|
||||
|
||||
if (!StackUtils.equals(entity.worldObj.getBlock(rest.posX, rest.posY, rest.posZ), entry.getKey()))
|
||||
continue;
|
||||
|
||||
int meta = entity.worldObj.getBlockMetadata(rest.posX, rest.posY, rest.posZ);
|
||||
if (StackUtils.equals(Blocks.leaves, entry.getKey()))
|
||||
meta = meta & 3;
|
||||
if (entry.getKey().getItemDamage() != meta)
|
||||
continue;
|
||||
|
||||
// We matched, replace the leaf block with ours and set the ersatz genome
|
||||
((ITreeRoot) AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees")).setLeaves(entity.worldObj, entry.getValue(), null, rest.posX, rest.posY, rest.posZ);
|
||||
// Now let's pollinate
|
||||
nursery = (IButterflyNursery) entity.worldObj.getTileEntity(rest.posX, rest.posY, rest.posZ);
|
||||
else {
|
||||
IPollinatable pollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
if (pollinatable instanceof IButterflyNursery) {
|
||||
nursery = (IButterflyNursery) pollinatable;
|
||||
}
|
||||
}
|
||||
|
||||
if (nursery == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
package forestry.lepidopterology.entities;
|
||||
|
||||
import forestry.api.genetics.IPollinatable;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.core.utils.GeneticsUtil;
|
||||
|
||||
public class AIButterflyPollinate extends AIButterflyInteract {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class AIButterflyPollinate extends AIButterflyInteract {
|
||||
if (entity.cooldownPollination > 0)
|
||||
return false;
|
||||
|
||||
IPollinatable pollinatable = Utils.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
IPollinatable pollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.worldObj, rest.posX, rest.posY, rest.posZ);
|
||||
if (pollinatable == null)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -991,6 +991,10 @@ public class PluginArboriculture extends ForestryPlugin {
|
||||
TreeTemplates.templateAsGenome(TreeTemplates.getBirchTemplate())));
|
||||
AlleleManager.ersatzSpecimen.put(new ItemStack(Blocks.leaves, 1, 3), new Tree(
|
||||
TreeTemplates.templateAsGenome(TreeTemplates.getJungleTemplate())));
|
||||
AlleleManager.ersatzSpecimen.put(new ItemStack(Blocks.leaves2, 1, 0), new Tree(
|
||||
TreeTemplates.templateAsGenome(TreeTemplates.getAcaciaTemplate())));
|
||||
AlleleManager.ersatzSpecimen.put(new ItemStack(Blocks.leaves2, 1, 1), new Tree(
|
||||
TreeTemplates.templateAsGenome(TreeTemplates.getDarkOakTemplate())));
|
||||
|
||||
AlleleManager.ersatzSaplings.put(new ItemStack(Blocks.sapling, 1, 0), new Tree(
|
||||
TreeTemplates.templateAsGenome(TreeTemplates.getOakTemplate())));
|
||||
|
||||
Reference in new issue
Block a user