use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCrusher in project minecolonies by ldtteam.
the class EntityAIWorkCrusher method crush.
/**
* The crushing process.
*
* @return the next AiState to go to.
*/
protected IAIState crush() {
if (walkToBuilding()) {
return getState();
}
worker.getCitizenData().setVisibleStatus(CRUSHING);
job.setProgress(job.getProgress() + TICK_DELAY);
final BuildingCrusher crusherBuilding = getOwnBuilding();
WorkerUtil.faceBlock(crusherBuilding.getPosition(), worker);
if (currentRecipeStorage == null) {
currentRecipeStorage = crusherBuilding.getCurrentRecipe();
}
if ((getState() != CRAFT && crusherBuilding.getCurrentDailyQuantity() >= crusherBuilding.getCrusherMode().getB()) || currentRecipeStorage == null) {
return START_WORKING;
}
final IAIState check = checkForItems(currentRecipeStorage);
if (job.getProgress() > MAX_LEVEL - Math.min((getSecondarySkillLevel() / 2) + 1, MAX_LEVEL)) {
job.setProgress(0);
if (check == CRAFT) {
if (getState() != CRAFT) {
crusherBuilding.setCurrentDailyQuantity(crusherBuilding.getCurrentDailyQuantity() + 1);
if (crusherBuilding.getCurrentDailyQuantity() >= crusherBuilding.getCrusherMode().getB()) {
incrementActionsDoneAndDecSaturation();
}
}
if (currentRequest != null) {
currentRequest.addDelivery(currentRecipeStorage.getPrimaryOutput());
}
worker.swing(Hand.MAIN_HAND);
job.setCraftCounter(job.getCraftCounter() + 1);
currentRecipeStorage.fullfillRecipe(getLootContext(), ImmutableList.of(worker.getItemHandlerCitizen()));
worker.decreaseSaturationForContinuousAction();
worker.getCitizenExperienceHandler().addExperience(0.1);
} else if (getState() != CRAFT) {
currentRecipeStorage = crusherBuilding.getCurrentRecipe();
final int requestQty = Math.min((crusherBuilding.getCrusherMode().getB() - crusherBuilding.getCurrentDailyQuantity()) * 2, STACKSIZE);
if (requestQty <= 0) {
return START_WORKING;
}
final ItemStack stack = currentRecipeStorage.getInput().get(0).getItemStack().copy();
stack.setCount(requestQty);
checkIfRequestForItemExistOrCreateAsynch(stack);
return START_WORKING;
} else {
return check;
}
}
if (check == CRAFT) {
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(currentRecipeStorage.getInput().get(0).getItemStack().copy(), crusherBuilding.getID()), worker);
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(currentRecipeStorage.getPrimaryOutput().copy(), crusherBuilding.getID().below()), worker);
SoundUtils.playSoundAtCitizen(world, getOwnBuilding().getID(), SoundEvents.STONE_BREAK);
}
return getState();
}
use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingCrusher in project minecolonies by Minecolonies.
the class EntityAIWorkCrusher method crush.
/**
* The crushing process.
*
* @return the next AiState to go to.
*/
protected IAIState crush() {
if (walkToBuilding()) {
return getState();
}
worker.getCitizenData().setVisibleStatus(CRUSHING);
job.setProgress(job.getProgress() + TICK_DELAY);
final BuildingCrusher crusherBuilding = building;
WorkerUtil.faceBlock(crusherBuilding.getPosition(), worker);
final IRecipeStorage recipeMode = crusherBuilding.getSetting(BuildingCrusher.MODE).getValue(crusherBuilding);
final int dailyLimit = crusherBuilding.getSetting(BuildingCrusher.DAILY_LIMIT).getValue();
if (currentRecipeStorage == null) {
currentRecipeStorage = recipeMode;
}
if ((getState() != CRAFT && crusherBuilding.getCurrentDailyQuantity() >= dailyLimit) || currentRecipeStorage == null) {
return START_WORKING;
}
final IAIState check = checkForItems(currentRecipeStorage);
if (job.getProgress() > MAX_LEVEL - Math.min((getSecondarySkillLevel() / 2) + 1, MAX_LEVEL)) {
job.setProgress(0);
if (check == CRAFT) {
if (getState() != CRAFT) {
crusherBuilding.setCurrentDailyQuantity(crusherBuilding.getCurrentDailyQuantity() + 1);
if (crusherBuilding.getCurrentDailyQuantity() >= dailyLimit) {
incrementActionsDoneAndDecSaturation();
}
}
if (currentRequest != null) {
currentRequest.addDelivery(currentRecipeStorage.getPrimaryOutput());
}
worker.swing(Hand.MAIN_HAND);
job.setCraftCounter(job.getCraftCounter() + 1);
currentRecipeStorage.fullfillRecipe(getLootContext(), ImmutableList.of(worker.getItemHandlerCitizen()));
worker.decreaseSaturationForContinuousAction();
worker.getCitizenExperienceHandler().addExperience(0.1);
} else if (getState() != CRAFT) {
currentRecipeStorage = recipeMode;
final int requestQty = Math.min((dailyLimit - crusherBuilding.getCurrentDailyQuantity()) * 2, STACKSIZE);
if (requestQty <= 0) {
return START_WORKING;
}
final ItemStack stack = currentRecipeStorage.getInput().get(0).getItemStack().copy();
stack.setCount(requestQty);
checkIfRequestForItemExistOrCreateAsync(stack);
return START_WORKING;
} else {
return check;
}
}
if (check == CRAFT) {
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(currentRecipeStorage.getInput().get(0).getItemStack().copy(), crusherBuilding.getID()), worker);
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(currentRecipeStorage.getPrimaryOutput().copy(), crusherBuilding.getID().below()), worker);
SoundUtils.playSoundAtCitizen(world, building.getID(), SoundEvents.STONE_BREAK);
}
return getState();
}
Aggregations