use of com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage 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.network.messages.client.LocalizedParticleEffectMessage in project minecolonies by ldtteam.
the class EntityAIWorkSifter method sift.
/**
* The sifting process.
*
* @return the next AiState to go to.
*/
protected IAIState sift() {
final BuildingSifter sifterBuilding = getOwnBuilding();
// Go idle if we can't do any more today
if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity()) {
return IDLE;
}
if (walkToBuilding()) {
return getState();
}
if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
return INVENTORY_FULL;
}
if (currentRecipeStorage == null) {
final ICraftingBuildingModule module = getOwnBuilding().getFirstModuleOccurance(BuildingSifter.CraftingModule.class);
currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
}
if (currentRecipeStorage == null) {
if (InventoryUtils.getCountFromBuilding(sifterBuilding, i -> ModTags.meshes.contains(i.getItem())) == 0) {
if (InventoryUtils.getItemCountInProvider(worker, i -> ModTags.meshes.contains(i.getItem())) > 0) {
// We don't want the mesh in our inventory, we 'craft' out of the building
incrementActionsDone();
return INVENTORY_FULL;
}
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(SIFTER_NO_MESH), ChatPriority.IMPORTANT));
setDelay(NO_MESH_DELAY);
}
}
if (!ItemStackUtils.isEmpty(worker.getMainHandItem())) {
worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
}
if (!ItemStackUtils.isEmpty(worker.getOffhandItem())) {
worker.setItemInHand(Hand.OFF_HAND, ItemStack.EMPTY);
}
progress = 0;
return START_WORKING;
}
final ItemStack meshItem = currentRecipeStorage.getCraftingTools().get(0);
final ItemStack inputItem = currentRecipeStorage.getCleanedInput().stream().map(ItemStorage::getItemStack).filter(item -> !ItemStackUtils.compareItemStacksIgnoreStackSize(item, meshItem, false, true)).findFirst().orElse(ItemStack.EMPTY);
if (meshItem.isEmpty() || inputItem.isEmpty()) {
currentRecipeStorage = null;
return getState();
}
if (!inputItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getMainHandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getMainHandItem(), inputItem))) {
worker.setItemInHand(Hand.MAIN_HAND, inputItem);
}
if (!meshItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getOffhandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getOffhandItem(), meshItem, false, true))) {
worker.setItemInHand(Hand.OFF_HAND, meshItem);
}
WorkerUtil.faceBlock(getOwnBuilding().getPosition(), worker);
progress++;
if (progress > MAX_LEVEL - (getEffectiveSkillLevel(getSecondarySkillLevel()) / 2)) {
progress = 0;
sifterBuilding.setCurrentDailyQuantity(sifterBuilding.getCurrentDailyQuantity() + 1);
if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity() || worker.getRandom().nextInt(ONE_HUNDRED_PERCENT) < CHANCE_TO_DUMP_INV) {
incrementActionsDoneAndDecSaturation();
}
if (!currentRecipeStorage.fullfillRecipe(getLootContext(), sifterBuilding.getHandlers())) {
currentRecipeStorage = null;
return getState();
}
worker.decreaseSaturationForContinuousAction();
worker.getCitizenExperienceHandler().addExperience(0.2);
}
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(meshItem, sifterBuilding.getID()), worker);
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(inputItem, sifterBuilding.getID().below()), worker);
worker.swing(Hand.MAIN_HAND);
SoundUtils.playSoundAtCitizen(world, getOwnBuilding().getID(), SoundEvents.LEASH_KNOT_BREAK);
return getState();
}
use of com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage in project minecolonies by Minecolonies.
the class EntityAIWorkSifter method sift.
/**
* The sifting process.
*
* @return the next AiState to go to.
*/
protected IAIState sift() {
final BuildingSifter sifterBuilding = building;
// Go idle if we can't do any more today
if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity()) {
return IDLE;
}
if (walkToBuilding()) {
return getState();
}
if (InventoryUtils.isItemHandlerFull(worker.getInventoryCitizen())) {
return INVENTORY_FULL;
}
if (currentRecipeStorage == null) {
final ICraftingBuildingModule module = building.getFirstModuleOccurance(BuildingSifter.CraftingModule.class);
currentRecipeStorage = module.getFirstFulfillableRecipe(ItemStackUtils::isEmpty, 1, false);
}
if (currentRecipeStorage == null) {
if (InventoryUtils.hasBuildingEnoughElseCount(sifterBuilding, i -> ModTags.meshes.contains(i.getItem()), 1) == 0) {
if (InventoryUtils.getItemCountInProvider(worker, i -> ModTags.meshes.contains(i.getItem())) > 0) {
// We don't want the mesh in our inventory, we 'craft' out of the building
incrementActionsDone();
return INVENTORY_FULL;
}
if (worker.getCitizenData() != null) {
worker.getCitizenData().triggerInteraction(new StandardInteraction(new TranslationTextComponent(SIFTER_NO_MESH), ChatPriority.IMPORTANT));
setDelay(NO_MESH_DELAY);
}
}
if (!ItemStackUtils.isEmpty(worker.getMainHandItem())) {
worker.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
}
if (!ItemStackUtils.isEmpty(worker.getOffhandItem())) {
worker.setItemInHand(Hand.OFF_HAND, ItemStack.EMPTY);
}
progress = 0;
return START_WORKING;
}
final ItemStack meshItem = currentRecipeStorage.getCraftingTools().get(0);
final ItemStack inputItem = currentRecipeStorage.getCleanedInput().stream().map(ItemStorage::getItemStack).filter(item -> !ItemStackUtils.compareItemStacksIgnoreStackSize(item, meshItem, false, true)).findFirst().orElse(ItemStack.EMPTY);
if (meshItem.isEmpty() || inputItem.isEmpty()) {
currentRecipeStorage = null;
return getState();
}
if (!inputItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getMainHandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getMainHandItem(), inputItem))) {
worker.setItemInHand(Hand.MAIN_HAND, inputItem);
}
if (!meshItem.isEmpty() && (ItemStackUtils.isEmpty(worker.getOffhandItem()) || ItemStackUtils.compareItemStacksIgnoreStackSize(worker.getOffhandItem(), meshItem, false, true))) {
worker.setItemInHand(Hand.OFF_HAND, meshItem);
}
WorkerUtil.faceBlock(building.getPosition(), worker);
progress++;
if (progress > MAX_LEVEL - (getEffectiveSkillLevel(getSecondarySkillLevel()) / 2)) {
progress = 0;
sifterBuilding.setCurrentDailyQuantity(sifterBuilding.getCurrentDailyQuantity() + 1);
if (sifterBuilding.getCurrentDailyQuantity() >= sifterBuilding.getMaxDailyQuantity() || worker.getRandom().nextInt(ONE_HUNDRED_PERCENT) < CHANCE_TO_DUMP_INV) {
incrementActionsDoneAndDecSaturation();
}
if (!currentRecipeStorage.fullfillRecipe(getLootContext(), sifterBuilding.getHandlers())) {
currentRecipeStorage = null;
return getState();
}
worker.decreaseSaturationForContinuousAction();
worker.getCitizenExperienceHandler().addExperience(0.2);
}
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(meshItem, sifterBuilding.getID()), worker);
Network.getNetwork().sendToTrackingEntity(new LocalizedParticleEffectMessage(inputItem, sifterBuilding.getID().below()), worker);
worker.swing(Hand.MAIN_HAND);
SoundUtils.playSoundAtCitizen(world, building.getID(), SoundEvents.LEASH_KNOT_BREAK);
return getState();
}
use of com.minecolonies.coremod.network.messages.client.LocalizedParticleEffectMessage 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