mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 01:04:12 +00:00
Merge pull request #3 from GTNewHorizons/limit_butterflies_distance_from_home
Backport butterflys staying close to home
This commit is contained in:
6 files changed
+23
-5
No files matched your search
@@ -257,3 +257,7 @@ def getBuildNumber() {
|
||||
return "$System.env.BUILD_NUMBER" != "null" ? "$System.env.BUILD_NUMBER" : "0"
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main { output.resourcesDir = output.classesDir }
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class ButterflySpawner implements ILeafTickHandler {
|
||||
if (world.rand.nextFloat() >= tree.getGenome().getSappiness() * tree.getGenome().getYield()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
IButterfly spawn = ButterflyManager.butterflyRoot.getIndividualTemplates().get(world.rand.nextInt(ButterflyManager.butterflyRoot.getIndividualTemplates().size()));
|
||||
if (world.rand.nextFloat() >= spawn.getGenome().getPrimary().getRarity() * 0.5f) {
|
||||
return false;
|
||||
|
||||
@@ -23,6 +23,7 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
@@ -69,6 +70,7 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
public static final int EXHAUSTION_REST = 1000;
|
||||
public static final int EXHAUSTION_CONSUMPTION = 100 * EXHAUSTION_REST;
|
||||
public static final int MAX_LIFESPAN = 24000 * 7; // one minecraft week in ticks
|
||||
private int maximumHomeDistance = 64;
|
||||
|
||||
private Vec3 flightTarget;
|
||||
private int exhaustion;
|
||||
@@ -89,10 +91,11 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
public EntityButterfly(World world, IButterfly butterfly) {
|
||||
public EntityButterfly(World world, IButterfly butterfly, int x, int y, int z) {
|
||||
super(world);
|
||||
setDefaults();
|
||||
setIndividual(butterfly);
|
||||
setHomeArea(x, y, z, maximumHomeDistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -194,6 +197,13 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
@Override
|
||||
public float getBlockPathWeight(int x, int y, int z) {
|
||||
float weight = 0.0f;
|
||||
final ChunkCoordinates home = getHomePosition();
|
||||
double distanceToHome = home.getDistanceSquared(x, y, z);
|
||||
|
||||
if(!isWithinHomeDistanceFromPosition(distanceToHome)){
|
||||
|
||||
weight -= 7.5f + 0.005 * (distanceToHome / 4);
|
||||
}
|
||||
|
||||
if (!getButterfly().isAcceptedEnvironment(worldObj, x, y, z)) {
|
||||
weight -= 15.0f;
|
||||
@@ -232,6 +242,10 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
return weight;
|
||||
}
|
||||
|
||||
private boolean isWithinHomeDistanceFromPosition(double distanceToHome) {
|
||||
return distanceToHome < (maximumHomeDistance * maximumHomeDistance);
|
||||
}
|
||||
|
||||
private int getFluidDepth(int x, int z) {
|
||||
Chunk chunk = worldObj.getChunkFromBlockCoords(x, z);
|
||||
int xx = x & 15;
|
||||
|
||||
@@ -149,7 +149,7 @@ public class ButterflyHelper extends SpeciesRoot implements IButterflyRoot {
|
||||
|
||||
@Override
|
||||
public EntityButterfly spawnButterflyInWorld(World world, IButterfly butterfly, double x, double y, double z) {
|
||||
return EntityUtil.spawnEntity(world, new EntityButterfly(world, butterfly), x, y, z);
|
||||
return EntityUtil.spawnEntity(world, new EntityButterfly(world, butterfly, (int)x, (int)y, (int)z), x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -133,7 +133,7 @@ public class ItemButterflyGE extends ItemGE {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (EntityUtil.spawnEntity(entityItem.worldObj, new EntityButterfly(entityItem.worldObj, butterfly), entityItem.posX, entityItem.posY, entityItem.posZ) != null) {
|
||||
if (EntityUtil.spawnEntity(entityItem.worldObj, new EntityButterfly(entityItem.worldObj, butterfly, (int)entityItem.posX, (int)entityItem.posY, (int)entityItem.posZ), entityItem.posX, entityItem.posY, entityItem.posZ) != null) {
|
||||
if (entityItem.getEntityItem().stackSize > 1) {
|
||||
entityItem.getEntityItem().stackSize--;
|
||||
} else {
|
||||
|
||||
@@ -81,7 +81,7 @@ public class RenderButterflyItem implements IItemRenderer {
|
||||
}
|
||||
|
||||
if (entity == null) {
|
||||
entity = new EntityButterfly(Proxies.common.getRenderWorld(), butterfly);
|
||||
entity = new EntityButterfly(Proxies.common.getRenderWorld(), butterfly, 0, 0, 0);
|
||||
} else {
|
||||
entity.setIndividual(butterfly);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user