mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-26 14:53:05 +00:00
Fix #701 Improve BeekeepingLogic and network performance.
Improve rendering performance of saplings and butterflies too
This commit is contained in:
1 parent
d61096e1a9
commit
1249ccf983
34 files changed
+404
-217
No files matched your search
@@ -36,6 +36,7 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
|
||||
private static final int MAX_POLLINATION_ATTEMPTS = 20;
|
||||
private static final int totalBreedingTime = Defaults.APIARY_BREEDING_TIME;
|
||||
private static final int ticksPerCheckCanWork = 10;
|
||||
|
||||
private final IBeeHousing housing;
|
||||
private final boolean housingSupportsMultipleErrorStates;
|
||||
@@ -50,8 +51,10 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
private final Stack<ItemStack> spawn = new Stack<ItemStack>();
|
||||
|
||||
// Cached flowers check
|
||||
private Boolean hasFlowersCached = false;
|
||||
private boolean hasFlowersCached = false;
|
||||
private int hasFlowersCooldown = 0;
|
||||
private boolean canWorkCached = false;
|
||||
private int canWorkCooldown = 0;
|
||||
|
||||
public BeekeepingLogic(IBeeHousing housing) {
|
||||
this.housing = housing;
|
||||
@@ -125,6 +128,16 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
|
||||
@Override
|
||||
public boolean canWork() {
|
||||
if (canWorkCooldown > 0) {
|
||||
canWorkCooldown--;
|
||||
} else {
|
||||
canWorkCached = checkCanWork();
|
||||
canWorkCooldown = ticksPerCheckCanWork;
|
||||
}
|
||||
return canWorkCached;
|
||||
}
|
||||
|
||||
private boolean checkCanWork() {
|
||||
if (housingSupportsMultipleErrorStates) {
|
||||
Set<IErrorState> errorStates = housing.getErrorStates();
|
||||
for (IErrorState errorState : errorStates) {
|
||||
@@ -132,8 +145,6 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
}
|
||||
}
|
||||
|
||||
this.queen = null;
|
||||
|
||||
boolean hasSpace = addPendingProducts();
|
||||
|
||||
if (hasBreedablePrincess()) {
|
||||
@@ -168,7 +179,12 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
private Boolean hasFlowers() {
|
||||
if (hasFlowersCooldown <= 0) {
|
||||
hasFlowersCached = queen.hasFlower(housing);
|
||||
hasFlowersCooldown = PluginApiculture.ticksPerBeeWorkCycle;
|
||||
hasFlowersCooldown = PluginApiculture.ticksPerBeeWorkCycle / ticksPerCheckCanWork;
|
||||
|
||||
// check more often if we haven't found flowers
|
||||
if (!hasFlowersCached) {
|
||||
hasFlowersCooldown /= 2;
|
||||
}
|
||||
} else {
|
||||
hasFlowersCooldown--;
|
||||
}
|
||||
@@ -268,24 +284,29 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
|
||||
return housingErrorState != EnumErrorCode.NOSPACE;
|
||||
}
|
||||
|
||||
|
||||
/** Checks if a queen is alive. Much faster than reading the whole bee nbt */
|
||||
private static boolean isQueenAlive(ItemStack queenStack) {
|
||||
NBTTagCompound nbtTagCompound = queenStack.getTagCompound();
|
||||
int health = nbtTagCompound.getInteger("Health");
|
||||
return health > 0;
|
||||
}
|
||||
|
||||
private boolean hasHealthyQueen() {
|
||||
boolean hasQueen = true;
|
||||
EnumErrorCode housingErrorState = null;
|
||||
|
||||
if (housing.getQueen() == null || !ForestryItem.beeQueenGE.isItemEqual(housing.getQueen())) {
|
||||
ItemStack queenStack = housing.getQueen();
|
||||
|
||||
if (queenStack == null || !ForestryItem.beeQueenGE.isItemEqual(housing.getQueen())) {
|
||||
housingErrorState = EnumErrorCode.NOQUEEN;
|
||||
hasQueen = false;
|
||||
} else {
|
||||
IBee queen = BeeManager.beeRoot.getMember(housing.getQueen());
|
||||
// Kill dying queens
|
||||
if (!queen.isAlive()) {
|
||||
killQueen(queen);
|
||||
housingErrorState = EnumErrorCode.OK;
|
||||
hasQueen = false;
|
||||
} else {
|
||||
this.queen = queen;
|
||||
}
|
||||
queen = null;
|
||||
} else if (!isQueenAlive(queenStack)) {
|
||||
killQueen(queen);
|
||||
housingErrorState = EnumErrorCode.OK;
|
||||
hasQueen = false;
|
||||
queen = null;
|
||||
}
|
||||
|
||||
if (housingSupportsMultipleErrorStates) {
|
||||
@@ -296,6 +317,10 @@ public class BeekeepingLogic implements IBeekeepingLogic {
|
||||
}
|
||||
}
|
||||
|
||||
if (hasQueen && queen == null) {
|
||||
queen = BeeManager.beeRoot.getMember(queenStack);
|
||||
}
|
||||
|
||||
return hasQueen;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user