mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 12:09:39 +00:00
Move go home to get getBlockPathWeight
This commit is contained in:
1 parent
c4ecdde110
commit
904293f407
6 files changed
+19
-50
No files matched your search
@@ -715,7 +715,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
for(IInternalBlock block : internalBlocks){
|
||||
BlockPos pos = block.getPos();
|
||||
if(world.isAirBlock(pos)){
|
||||
if(ButterflyUtils.spawnButterfly(nursery.getCaterpillar(), world, pos)){
|
||||
if(ButterflyUtils.spawnButterflyWithoutCheck(nursery.getCaterpillar(), world, pos)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -732,7 +732,7 @@ public class GreenhouseController extends RectangularMultiblockControllerBase im
|
||||
for(IInternalBlock block : internalBlocks){
|
||||
BlockPos pos = block.getPos();
|
||||
if(world.isAirBlock(pos)){
|
||||
if(ButterflyUtils.spawnButterfly(butterfly, world, pos)){
|
||||
if(ButterflyUtils.spawnButterflyWithoutCheck(butterfly, world, pos)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,7 @@ import forestry.api.arboriculture.ILeafTickHandler;
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.lepidopterology.entities.EntityButterfly;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -52,21 +50,16 @@ public class ButterflySpawner implements ILeafTickHandler {
|
||||
}
|
||||
|
||||
if (world.isAirBlock(pos.north())) {
|
||||
attemptButterflySpawn(world, spawn, pos.north());
|
||||
ButterflyUtils.attemptButterflySpawn(world, spawn, pos.north());
|
||||
} else if (world.isAirBlock(pos.south())) {
|
||||
attemptButterflySpawn(world, spawn, pos.south());
|
||||
ButterflyUtils.attemptButterflySpawn(world, spawn, pos.south());
|
||||
} else if (world.isAirBlock(pos.west())) {
|
||||
attemptButterflySpawn(world, spawn, pos.west());
|
||||
ButterflyUtils.attemptButterflySpawn(world, spawn, pos.west());
|
||||
} else if (world.isAirBlock(pos.east())) {
|
||||
attemptButterflySpawn(world, spawn, pos.east());
|
||||
ButterflyUtils.attemptButterflySpawn(world, spawn, pos.east());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) {
|
||||
EntityLiving entityLiving = ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), pos.getX(), pos.getY() + 0.1f, pos.getZ());
|
||||
Log.trace("Spawned a butterfly '%s' at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package forestry.lepidopterology;
|
||||
|
||||
import forestry.api.lepidopterology.ButterflyManager;
|
||||
import forestry.api.lepidopterology.IButterfly;
|
||||
import forestry.api.lepidopterology.IButterflyCocoon;
|
||||
import forestry.core.utils.Log;
|
||||
import forestry.lepidopterology.entities.EntityButterfly;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
@@ -11,7 +10,7 @@ import net.minecraft.world.World;
|
||||
|
||||
public class ButterflyUtils {
|
||||
|
||||
private static boolean attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) {
|
||||
static boolean attemptButterflySpawn(World world, IButterfly butterfly, BlockPos pos) {
|
||||
EntityLiving entityLiving = ButterflyManager.butterflyRoot.spawnButterflyInWorld(world, butterfly.copy(), pos.getX(), pos.getY() + 0.1f, pos.getZ());
|
||||
Log.trace("Spawned a butterfly '%s' at %s/%s/%s.", butterfly.getDisplayName(), pos.getX(), pos.getY(), pos.getZ());
|
||||
return entityLiving != null;
|
||||
@@ -32,8 +31,7 @@ public class ButterflyUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean spawnButterfly(IButterflyCocoon cocoon, World world, BlockPos pos){
|
||||
IButterfly butterfly = cocoon.getCaterpillar();
|
||||
public static boolean spawnButterflyWithoutCheck(IButterfly butterfly, World world, BlockPos pos){
|
||||
if (world.countEntities(EntityButterfly.class) > PluginLepidopterology.spawnConstraint) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class PluginLepidopterology extends BlankForestryPlugin {
|
||||
private static final String CONFIG_CATEGORY = "lepidopterology";
|
||||
public static int spawnConstraint = 100;
|
||||
public static int entityConstraint = 1000;
|
||||
public static int maxDistance = 256;
|
||||
public static int maxDistance = 64;
|
||||
private static boolean allowPollination = true;
|
||||
public static final Map<String, Float> spawnRaritys = Maps.newHashMap();
|
||||
private static boolean spawnButterflysFromLeaves = true;
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package forestry.lepidopterology.entities;
|
||||
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class AIButterflyGoHome extends AIButterflyMovement {
|
||||
|
||||
public AIButterflyGoHome(EntityButterfly entity) {
|
||||
super(entity);
|
||||
setMutexBits(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldExecute() {
|
||||
if (entity.isWithinHomeDistanceCurrentPosition()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
flightTarget = new Vec3d(entity.getHomePosition());
|
||||
if (flightTarget.equals(Vec3d.ZERO)) {
|
||||
if (entity.getState().doesMovement) {
|
||||
entity.setState(EnumButterflyState.HOVER);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
entity.setDestination(flightTarget);
|
||||
entity.setState(EnumButterflyState.FLYING);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -125,7 +125,6 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
tasks.addTask(11, new AIButterflyRest(this));
|
||||
tasks.addTask(12, new AIButterflyRise(this));
|
||||
tasks.addTask(12, new AIButterflyWander(this));
|
||||
tasks.addTask(13, new AIButterflyGoHome(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -229,6 +228,12 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
}
|
||||
|
||||
float weight = 0.0f;
|
||||
double distanceToHome = getHomePosition().distanceSq(pos);
|
||||
|
||||
if(!isWithinHomeDistanceFromPosition(distanceToHome)){
|
||||
|
||||
weight -= 7.5f + 0.005 * (distanceToHome / 4);
|
||||
}
|
||||
|
||||
if (!getButterfly().isAcceptedEnvironment(world, pos.getX(), pos.getY(), pos.getZ())) {
|
||||
weight -= 15.0f;
|
||||
@@ -269,6 +274,10 @@ public class EntityButterfly extends EntityCreature implements IEntityButterfly
|
||||
weight += world.getLightBrightness(pos);
|
||||
return weight;
|
||||
}
|
||||
|
||||
private boolean isWithinHomeDistanceFromPosition(double distanceToHome) {
|
||||
return distanceToHome < this.getMaximumHomeDistance() * this.getMaximumHomeDistance();
|
||||
}
|
||||
|
||||
private int getFluidDepth(BlockPos pos) {
|
||||
Chunk chunk = world.getChunkFromBlockCoords(pos);
|
||||
|
||||
Reference in new issue
Block a user