mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 04:22:32 +00:00
Prevent butterflies from converting vanilla leaves to Forestry leaves
This commit is contained in:
1 parent
d29aa13377
commit
0356a3f479
10 files changed
+42
-55
No files matched your search
@@ -721,7 +721,7 @@ public class Bee extends IndividualLiving implements IBee {
|
||||
continue;
|
||||
}
|
||||
|
||||
IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwner(), world, posBlock);
|
||||
IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(housing.getOwner(), world, posBlock, Config.pollinateVanillaTrees);
|
||||
|
||||
if (realPollinatable != null) {
|
||||
realPollinatable.mateWith(pollen);
|
||||
|
||||
@@ -436,13 +436,15 @@ public class TreeRoot extends SpeciesRoot implements ITreeRoot {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPollinatable tryConvertToPollinatable(@Nullable GameProfile owner, World world, BlockPos pos, IIndividual pollen) {
|
||||
Preconditions.checkArgument(pollen instanceof ITree, "pollen must be an instance of ITree");
|
||||
if (Config.pollinateVanillaTrees) {
|
||||
((ITree) pollen).setLeaves(world, owner, pos);
|
||||
return (IPollinatable) world.getTileEntity(pos);
|
||||
@Nullable
|
||||
public IPollinatable tryConvertToPollinatable(@Nullable GameProfile owner, World world, BlockPos pos, IIndividual individual) {
|
||||
Preconditions.checkArgument(individual instanceof ITree, "pollen must be an instance of ITree");
|
||||
ITree pollen = (ITree) individual;
|
||||
if (pollen.setLeaves(world, owner, pos)) {
|
||||
return TileUtil.getTile(world, pos, IPollinatable.class);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -156,7 +156,7 @@ public class ItemGermlingGE extends ItemGE implements IVariableFermentable, ICol
|
||||
return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
|
||||
}
|
||||
|
||||
IPollinatable pollinatable = GeneticsUtil.getOrCreatePollinatable(playerIn.getGameProfile(), worldIn, pos);
|
||||
IPollinatable pollinatable = GeneticsUtil.getOrCreatePollinatable(playerIn.getGameProfile(), worldIn, pos, true);
|
||||
if (pollinatable == null || !pollinatable.canMateWith(tree)) {
|
||||
return new ActionResult<>(EnumActionResult.FAIL, itemStackIn);
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public abstract class TileUtil {
|
||||
* see {@link BlockFlowerPot#getActualState(IBlockState, IBlockAccess, BlockPos)}
|
||||
*/
|
||||
@Nullable
|
||||
public static <T extends TileEntity> T getTile(IBlockAccess world, BlockPos pos, Class<T> tileClass) {
|
||||
public static <T> T getTile(IBlockAccess world, BlockPos pos, Class<T> tileClass) {
|
||||
TileEntity tileEntity;
|
||||
|
||||
if (world instanceof ChunkCache) {
|
||||
|
||||
@@ -33,6 +33,7 @@ import forestry.api.genetics.ISpeciesRootPollinatable;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyNursery;
|
||||
import forestry.core.genetics.ItemGE;
|
||||
import forestry.core.tiles.TileUtil;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -102,31 +103,27 @@ public class GeneticsUtil {
|
||||
* Returns an IPollinatable that can be mated. This will convert vanilla leaves to Forestry leaves.
|
||||
*/
|
||||
@Nullable
|
||||
public static IPollinatable getOrCreatePollinatable(@Nullable GameProfile owner, World world, final BlockPos pos) {
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof IPollinatable) {
|
||||
return (IPollinatable) tile;
|
||||
}
|
||||
|
||||
final IIndividual pollen = getPollen(world, pos);
|
||||
if (pollen != null) {
|
||||
ISpeciesRoot root = pollen.getGenome().getSpeciesRoot();
|
||||
if (root instanceof ISpeciesRootPollinatable) {
|
||||
return ((ISpeciesRootPollinatable) root).tryConvertToPollinatable(owner, world, pos, pollen);
|
||||
public static IPollinatable getOrCreatePollinatable(@Nullable GameProfile owner, World world, final BlockPos pos, boolean convertVanilla) {
|
||||
IPollinatable pollinatable = TileUtil.getTile(world, pos, IPollinatable.class);
|
||||
if (pollinatable == null && convertVanilla) {
|
||||
final IIndividual pollen = getPollen(world, pos);
|
||||
if (pollen != null) {
|
||||
ISpeciesRoot root = pollen.getGenome().getSpeciesRoot();
|
||||
if (root instanceof ISpeciesRootPollinatable) {
|
||||
ISpeciesRootPollinatable rootPollinatable = (ISpeciesRootPollinatable) root;
|
||||
pollinatable = rootPollinatable.tryConvertToPollinatable(owner, world, pos, pollen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return pollinatable;
|
||||
}
|
||||
|
||||
public static IButterflyNursery getOrCreateNursery(World world, BlockPos pos, GameProfile gameProfile) {
|
||||
|
||||
@Nullable
|
||||
public static IButterflyNursery getOrCreateNursery(@Nullable GameProfile gameProfile, World world, BlockPos pos, boolean convertVanilla) {
|
||||
IButterflyNursery nursery = getNursery(world, pos);
|
||||
|
||||
if (nursery == null) {
|
||||
if (nursery == null && convertVanilla) {
|
||||
IIndividual pollen = GeneticsUtil.getPollen(world, pos);
|
||||
|
||||
if (pollen != null && pollen instanceof ITree) {
|
||||
if (pollen instanceof ITree) {
|
||||
ITree treeLeave = (ITree) pollen;
|
||||
if (treeLeave.setLeaves(world, gameProfile, pos)) {
|
||||
nursery = getNursery(world, pos);
|
||||
@@ -140,14 +137,10 @@ public class GeneticsUtil {
|
||||
IIndividual pollen = GeneticsUtil.getPollen(world, pos);
|
||||
return pollen != null && pollen instanceof ITree;
|
||||
}
|
||||
|
||||
public static IButterflyNursery getNursery(World world, BlockPos pos) {
|
||||
TileEntity tileEntity = world.getTileEntity(pos);
|
||||
|
||||
if (tileEntity instanceof IButterflyNursery) {
|
||||
return (IButterflyNursery) tileEntity;
|
||||
}
|
||||
return null;
|
||||
@Nullable
|
||||
public static IButterflyNursery getNursery(World world, BlockPos pos) {
|
||||
return TileUtil.getTile(world, pos, IButterflyNursery.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,10 +152,9 @@ public class GeneticsUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
|
||||
if (tile instanceof ICheckPollinatable) {
|
||||
return ((ICheckPollinatable) tile).getPollen();
|
||||
ICheckPollinatable checkPollinatable = TileUtil.getTile(world, pos, ICheckPollinatable.class);
|
||||
if (checkPollinatable != null) {
|
||||
return checkPollinatable.getPollen();
|
||||
}
|
||||
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
|
||||
@@ -56,9 +56,8 @@ public class AIButterflyMate extends AIButterflyInteract {
|
||||
entity.cooldownMate = EntityButterfly.COOLDOWNS;
|
||||
}
|
||||
} else if (rest != null) {
|
||||
IPollinatable tile = GeneticsUtil.getOrCreatePollinatable(null, entity.world, rest);
|
||||
if (tile instanceof IButterflyNursery) {
|
||||
IButterflyNursery nursery = (IButterflyNursery) tile;
|
||||
IButterflyNursery nursery = GeneticsUtil.getOrCreateNursery(null, entity.world, rest, false);
|
||||
if (nursery != null) {
|
||||
if (nursery.canNurse(entity.getButterfly())) {
|
||||
nursery.setCaterpillar(entity.getButterfly().spawnCaterpillar(entity.world, nursery));
|
||||
//Log.finest("A butterfly '%s' laid an egg at %s/%s/%s.", entity.getButterfly().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class AIButterflyPollinate extends AIButterflyInteract {
|
||||
entity.setPollen(checkPollinatable.getPollen());
|
||||
// Log.finest("A butterfly '%s' grabbed a pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
} else if (checkPollinatable.canMateWith(entity.getPollen())) {
|
||||
IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.world, rest);
|
||||
IPollinatable realPollinatable = GeneticsUtil.getOrCreatePollinatable(null, entity.world, rest, false);
|
||||
if (realPollinatable != null) {
|
||||
realPollinatable.mateWith(entity.getPollen());
|
||||
// Log.finest("A butterfly '%s' unloaded pollen '%s' at %s/%s/%s.", entity.getButterfly().getIdent(), entity.getPollen().getIdent(), rest.posX, rest.posY, rest.posZ);
|
||||
|
||||
@@ -242,21 +242,15 @@ public class ButterflyRoot extends SpeciesRoot implements IButterflyRoot {
|
||||
if(isNurseryValid(nursery, caterpillar, gameProfile)){
|
||||
return true;
|
||||
}else if(createNursery && GeneticsUtil.canCreateNursery(world, nurseryPos)){
|
||||
nursery = GeneticsUtil.getOrCreateNursery(world, nurseryPos, gameProfile);
|
||||
nursery = GeneticsUtil.getOrCreateNursery(gameProfile, world, nurseryPos, false);
|
||||
return isNurseryValid(nursery, caterpillar, gameProfile);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isNurseryValid(IButterflyNursery nursery, IButterfly caterpillar, GameProfile gameProfile){
|
||||
if(nursery != null){
|
||||
if(!nursery.canNurse(caterpillar)){
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
private boolean isNurseryValid(@Nullable IButterflyNursery nursery, IButterfly caterpillar, GameProfile gameProfile) {
|
||||
return nursery != null && nursery.canNurse(caterpillar);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -241,7 +241,7 @@ public class ItemButterflyGE extends ItemGE implements ISpriteRegister, IColored
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
} else if (type == EnumFlutterType.CATERPILLAR) {
|
||||
IButterflyNursery nursery = GeneticsUtil.getOrCreateNursery(world, pos, player.getGameProfile());
|
||||
IButterflyNursery nursery = GeneticsUtil.getOrCreateNursery(player.getGameProfile(), world, pos, true);
|
||||
if (nursery != null) {
|
||||
if (!nursery.canNurse(flutter)) {
|
||||
return EnumActionResult.PASS;
|
||||
|
||||
Reference in new issue
Block a user