diff --git a/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java b/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java index df01cb05499..784a91b9988 100755 --- a/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java +++ b/src/main/java/com/minecolonies/api/entity/citizen/AbstractEntityCitizen.java @@ -623,13 +623,6 @@ public boolean checkCanDropLoot() */ public abstract ICitizenExperienceHandler getCitizenExperienceHandler(); - /** - * The Handler for all item related methods. - * - * @return the instance of the handler. - */ - public abstract ICitizenItemHandler getCitizenItemHandler(); - /** * The Handler for all inventory related methods. * @@ -672,8 +665,6 @@ public boolean checkCanDropLoot() public abstract void setCitizenJobHandler(ICitizenJobHandler citizenJobHandler); - public abstract void setCitizenItemHandler(ICitizenItemHandler citizenItemHandler); - public abstract void setCitizenExperienceHandler(ICitizenExperienceHandler citizenExperienceHandler); /** diff --git a/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenItemHandler.java b/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenItemHandler.java deleted file mode 100755 index c39aeb9dd05..00000000000 --- a/src/main/java/com/minecolonies/api/entity/citizen/citizenhandlers/ICitizenItemHandler.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.minecolonies.api.entity.citizen.citizenhandlers; - -import net.minecraft.core.BlockPos; -import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.item.ItemEntity; -import net.minecraft.world.item.ItemStack; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface ICitizenItemHandler -{ - /** - * Citizen will try to pick up a certain item. - * - * @param ItemEntity the item he wants to pickup. - */ - void tryPickupItemEntity(@NotNull ItemEntity ItemEntity); - - /** - * Removes the currently held item. - */ - void removeHeldItem(); - - /** - * Sets the currently held item. - * - * @param hand what hand we're setting - * @param slot from the inventory slot. - */ - void setHeldItem(InteractionHand hand, int slot); - - /** - * Sets the currently held for mainHand item. - * - * @param slot from the inventory slot. - */ - void setMainHeldItem(int slot); - - /** - * Swing entity arm, create sound and particle effects. - *

- * Will not break the block. - * - * @param blockPos Block position. - */ - void hitBlockWithToolInHand(@Nullable BlockPos blockPos); - - /** - * Swing entity arm, create sound and particle effects. - *

- * If breakBlock is true then it will break the block (different sound and particles), and damage the tool in the citizens hand. - * - * @param blockPos Block position. - * @param breakBlock if we want to break this block. - */ - void hitBlockWithToolInHand(@Nullable BlockPos blockPos, boolean breakBlock); - - /** - * Damage the current held item. - * - * @param hand hand the item is in. - * @param damage amount of damage. - */ - void damageItemInHand(InteractionHand hand, int damage); - - /** - * Pick up all items in a range around the citizen. - */ - void pickupItems(); - - /** - * Swing entity arm, create sound and particle effects. - *

- * This will break the block (different sound and particles), and damage the tool in the citizens hand. - * - * @param blockPos Block position. - */ - void breakBlockWithToolInHand(@Nullable BlockPos blockPos); - - /** - * Handles the dropping of items from the entity. - * - * @param itemstack to drop. - * @return the dropped item. - */ - ItemEntity entityDropItem(@NotNull ItemStack itemstack); - - /** - * Updates the armour damage after being hit. - * - * @param damage damage dealt. - */ - void updateArmorDamage(double damage); - - /** - * Apply mending to the armour. - * - * @param localXp the xp to add. - * @return the remaining xp. - */ - double applyMending(final double localXp); -} diff --git a/src/main/java/com/minecolonies/core/colony/jobs/JobKnight.java b/src/main/java/com/minecolonies/core/colony/jobs/JobKnight.java index 7ccbe0e30b0..5b52bbda689 100755 --- a/src/main/java/com/minecolonies/core/colony/jobs/JobKnight.java +++ b/src/main/java/com/minecolonies/core/colony/jobs/JobKnight.java @@ -1,5 +1,6 @@ package com.minecolonies.core.colony.jobs; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.component.DataComponents; import net.minecraft.resources.ResourceLocation; import com.minecolonies.api.client.render.modeltype.ModModelTypes; @@ -83,7 +84,7 @@ public boolean ignoresDamage(@NotNull final DamageSource damageSource) return true; } final AbstractEntityCitizen worker = this.getCitizen().getEntity().get(); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.OFF_HAND, InventoryUtils.findFirstSlotInItemHandlerWith(this.getCitizen().getInventory(), Items.SHIELD)); + CitizenItemUtils.setHeldItem(worker, InteractionHand.OFF_HAND, InventoryUtils.findFirstSlotInItemHandlerWith(this.getCitizen().getInventory(), Items.SHIELD)); worker.startUsingItem(InteractionHand.OFF_HAND); ItemStack shieldStack = worker.getInventoryCitizen().getHeldItem(InteractionHand.OFF_HAND); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java index eba5a152338..e1ed002e1fe 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIBasic.java @@ -35,6 +35,7 @@ import com.minecolonies.core.colony.jobs.AbstractJob; import com.minecolonies.core.colony.jobs.JobDeliveryman; import com.minecolonies.core.colony.requestsystem.resolvers.StationRequestResolver; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.entity.pathfinding.proxy.EntityCitizenWalkToProxy; import com.minecolonies.core.tileentities.TileEntityRack; import com.minecolonies.core.util.WorkerUtil; @@ -520,7 +521,7 @@ private boolean waitingForSomething() currentWorkingLocation.getZ(), DEFAULT_RANGE_FOR_DELAY)) { - worker.getCitizenItemHandler().hitBlockWithToolInHand(currentWorkingLocation); + CitizenItemUtils.hitBlockWithToolInHand(worker, currentWorkingLocation); } delay -= getTickRate(); if (delay <= 0) @@ -1278,13 +1279,13 @@ public final boolean holdEfficientTool(@NotNull final BlockState target, final B if (bestSlot >= 0) { worker.getCitizenData().setIdleAtJob(false); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, bestSlot); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, bestSlot); return true; } else if (bestSlot == NO_TOOL) { worker.getCitizenData().setIdleAtJob(false); - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); return true; } requestTool(target, pos); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java index 49bdfc66bf7..21dd5f88b0e 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/AbstractEntityAIInteract.java @@ -5,6 +5,7 @@ import com.minecolonies.core.MineColonies; import com.minecolonies.core.colony.buildings.AbstractBuilding; import com.minecolonies.core.colony.jobs.AbstractJob; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.item.ItemEntity; @@ -217,7 +218,7 @@ protected final boolean mineBlock( if (blockBreakAction == null) { //Break the block - worker.getCitizenItemHandler().breakBlockWithToolInHand(blockToMine); + CitizenItemUtils.breakBlockWithToolInHand(worker, blockToMine); } else { diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java index aa9ee490594..093c2b3ab7e 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAICrafting.java @@ -23,6 +23,7 @@ import com.minecolonies.core.colony.jobs.AbstractJobCrafter; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.network.messages.client.BlockParticleEffectMessage; import com.minecolonies.core.network.messages.client.LocalizedParticleEffectMessage; import net.minecraft.core.BlockPos; @@ -34,7 +35,6 @@ import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.storage.loot.LootParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams; -import net.neoforged.neoforge.network.PacketDistributor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -449,7 +449,7 @@ protected IAIState craft() job.setCraftCounter(job.getCraftCounter() + 1); if (toolSlot != -1) { - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); } if (job.getCraftCounter() >= job.getMaxCraftingCount()) diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAIRequestSmelter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAIRequestSmelter.java index 4230ab292ae..6946a4cebc4 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAIRequestSmelter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/AbstractEntityAIRequestSmelter.java @@ -24,6 +24,7 @@ import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.AbstractJobCrafter; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIBasic; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; @@ -740,7 +741,7 @@ private IAIState fillUpFurnace() { return getState(); } - worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo); + CitizenItemUtils.hitBlockWithToolInHand(worker, walkTo); InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler( worker.getInventoryCitizen(), smeltable, diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkAlchemist.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkAlchemist.java index 54f53f07bf6..b1c20691774 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkAlchemist.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkAlchemist.java @@ -19,6 +19,7 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingAlchemist; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobAlchemist; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.network.messages.client.BlockParticleEffectMessage; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; @@ -247,7 +248,7 @@ private IAIState harvestMistleToe() final int slot = InventoryUtils.getFirstSlotOfItemHandlerContainingEquipment(worker.getInventoryCitizen(), ModEquipmentTypes.shears.get(), TOOL_LEVEL_WOOD_OR_GOLD, building.getMaxEquipmentLevel()); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, slot); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, slot); worker.swing(InteractionHand.MAIN_HAND); world.playSound(null, @@ -262,7 +263,7 @@ private IAIState harvestMistleToe() worker.decreaseSaturationForContinuousAction(); InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), new ItemStack(ModItems.mistletoe, 1)); walkTo = null; - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); return INVENTORY_FULL; } } @@ -929,7 +930,7 @@ private IAIState fillUpBrewingStand() { return getState(); } - worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo); + CitizenItemUtils.hitBlockWithToolInHand(worker, walkTo); InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler( worker.getInventoryCitizen(), potion, @@ -988,7 +989,7 @@ else if (isEmpty(((BrewingStandBlockEntity) entity).getItem(INGREDIENT_SLOT))) { return getState(); } - worker.getCitizenItemHandler().hitBlockWithToolInHand(walkTo); + CitizenItemUtils.hitBlockWithToolInHand(worker, walkTo); InventoryUtils.transferXInItemHandlerIntoSlotInItemHandler( worker.getInventoryCitizen(), ingredient, diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkCrusher.java b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkCrusher.java index 9594a0d0944..cc8ef9364a9 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkCrusher.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/crafting/EntityAIWorkCrusher.java @@ -6,7 +6,7 @@ import com.minecolonies.api.entity.ai.statemachine.AITarget; import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; -import com.minecolonies.core.entity.pathfinding.navigation.AbstractAdvancedPathNavigate; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.api.util.SoundUtils; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingCrusher; @@ -218,7 +218,7 @@ protected IAIState craft() worker.setItemInHand(InteractionHand.MAIN_HAND, currentRecipeStorage.getCleanedInput().get(worker.getRandom().nextInt(currentRecipeStorage.getCleanedInput().size())).getItemStack().copy()); worker.setItemInHand(InteractionHand.OFF_HAND, currentRecipeStorage.getPrimaryOutput().copy()); - worker.getCitizenItemHandler().hitBlockWithToolInHand(building.getPosition()); + CitizenItemUtils.hitBlockWithToolInHand(worker, building.getPosition()); currentRequest = job.getCurrentTask(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java index 8f66ef18067..44438aa6b84 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/AbstractEntityAIFight.java @@ -12,6 +12,7 @@ import com.minecolonies.core.colony.buildings.AbstractBuildingGuards; import com.minecolonies.core.colony.jobs.AbstractJobGuard; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ArmorItem; @@ -125,7 +126,7 @@ private IAIState prepare() stack -> !ItemStackUtils.isEmpty(stack) && ItemStackUtils.doesItemServeAsWeapon(stack) && ItemStackUtils.hasEquipmentLevel(stack, tool, 0, building.getMaxEquipmentLevel()), - itemStack -> worker.getCitizenItemHandler().setMainHeldItem(itemStack)); + itemStack -> CitizenItemUtils.setMainHeldItem(worker, itemStack)); } equipInventoryArmor(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java index 02e1357ebc1..4efb9fea24d 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/KnightCombatAI.java @@ -11,6 +11,7 @@ import com.minecolonies.api.equipment.ModEquipmentTypes; import com.minecolonies.api.util.*; import com.minecolonies.api.util.constant.ColonyConstants; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.MineColonies; @@ -108,7 +109,7 @@ protected IAIState attackProtect() if (shieldSlot != -1 && target != null && target.isAlive() && nextAttackTime - user.level().getGameTime() >= MIN_TIME_TO_ATTACK && user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(SHIELD_USAGE) > 0) { - user.getCitizenItemHandler().setHeldItem(InteractionHand.OFF_HAND, shieldSlot); + CitizenItemUtils.setHeldItem(user, InteractionHand.OFF_HAND, shieldSlot); user.startUsingItem(InteractionHand.OFF_HAND); // Apply the colony Flag to the shield @@ -133,7 +134,7 @@ public boolean canAttack() if (weaponSlot != -1) { - user.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, weaponSlot); + CitizenItemUtils.setHeldItem(user, InteractionHand.MAIN_HAND, weaponSlot); return true; } @@ -184,7 +185,7 @@ protected void doAttack(final LivingEntity target) user.stopUsingItem(); user.decreaseSaturationForContinuousAction(); user.getCitizenData().setVisibleStatus(KNIGHT_COMBAT); - user.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(user, InteractionHand.MAIN_HAND, 1); } /** diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java index c0ccc72991b..f6e5b146480 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/RangerCombatAI.java @@ -6,6 +6,7 @@ import com.minecolonies.api.equipment.ModEquipmentTypes; import com.minecolonies.api.util.*; import com.minecolonies.api.util.constant.ColonyConstants; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.entity.pathfinding.PathfindingUtils; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; import com.minecolonies.core.entity.pathfinding.PathingOptions; @@ -18,11 +19,8 @@ import com.minecolonies.core.entity.ai.combat.CombatUtils; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.entity.other.CustomArrowEntity; -import com.minecolonies.core.entity.pathfinding.PathfindingUtils; -import com.minecolonies.core.entity.pathfinding.PathingOptions; import com.minecolonies.core.entity.pathfinding.navigation.MinecoloniesAdvancedPathNavigate; import com.minecolonies.core.entity.pathfinding.pathjobs.*; -import net.minecraft.core.component.DataComponents; import net.minecraft.network.chat.contents.TranslatableContents; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -35,7 +33,6 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.item.enchantment.Enchantments; -import net.neoforged.neoforge.registries.DeferredRegister; import static com.minecolonies.api.research.util.ResearchConstants.*; import static com.minecolonies.api.util.constant.GuardConstants.*; @@ -111,7 +108,7 @@ public boolean canAttack() if (weaponSlot != -1) { - user.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, weaponSlot); + CitizenItemUtils.setHeldItem(user, InteractionHand.MAIN_HAND, weaponSlot); if (nextAttackTime - BOW_HOLDING_DELAY >= user.level().getGameTime() && !user.isUsingItem()) { user.startUsingItem(InteractionHand.MAIN_HAND); @@ -190,7 +187,7 @@ protected void doAttack(final LivingEntity target) } target.setLastHurtByMob(user); - user.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(user, InteractionHand.MAIN_HAND, 1); user.stopUsingItem(); user.decreaseSaturationForContinuousAction(); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAIArcherTraining.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAIArcherTraining.java index 4053dd26eff..d3eebf27b7e 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAIArcherTraining.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAIArcherTraining.java @@ -11,6 +11,7 @@ import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingArchery; import com.minecolonies.core.colony.jobs.JobArcherTraining; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.util.WorkerUtil; import net.minecraft.world.entity.MoverType; import net.minecraft.world.entity.projectile.Arrow; @@ -187,7 +188,7 @@ protected IAIState shoot() if (worker.getRandom().nextBoolean()) { - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); } worker.stopUsingItem(); this.incrementActionsDoneAndDecSaturation(); @@ -232,7 +233,7 @@ protected boolean isSetup() } final int bowSlot = InventoryUtils.getFirstSlotOfItemHandlerContainingEquipment(getInventory(), ModEquipmentTypes.bow.get(), 0, building.getMaxEquipmentLevel()); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, bowSlot); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, bowSlot); return true; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAICombatTraining.java b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAICombatTraining.java index b93382dee90..4e98efbe600 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAICombatTraining.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/guard/training/EntityAICombatTraining.java @@ -10,6 +10,7 @@ import com.minecolonies.api.util.SoundUtils; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingCombatAcademy; import com.minecolonies.core.colony.jobs.JobCombatTraining; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.util.WorkerUtil; import net.minecraft.world.item.Items; import net.minecraft.world.InteractionHand; @@ -185,7 +186,7 @@ private IAIState attack() if (shieldSlot != -1) { worker.playSound(SoundEvents.SHIELD_BLOCK, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(worker.getRandom())); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.OFF_HAND, shieldSlot); + CitizenItemUtils.setHeldItem(worker, InteractionHand.OFF_HAND, shieldSlot); worker.startUsingItem(InteractionHand.OFF_HAND); worker.getLookControl().setLookAt(trainingPartner, (float) TURN_AROUND, (float) TURN_AROUND); } @@ -195,7 +196,7 @@ private IAIState attack() worker.swing(InteractionHand.MAIN_HAND); worker.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(worker.getRandom())); trainingPartner.hurt(world.damageSources().source(DamageSourceKeys.TRAINING, worker), 0.0F); - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); } worker.getNavigation().moveAwayFromXYZ(trainingPartner.blockPosition(), 4.0, 1.0, true); targetCounter++; @@ -278,7 +279,7 @@ private IAIState attackDummy() if (shieldSlot != -1) { worker.playSound(SoundEvents.SHIELD_BLOCK, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(worker.getRandom())); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.OFF_HAND, shieldSlot); + CitizenItemUtils.setHeldItem(worker, InteractionHand.OFF_HAND, shieldSlot); worker.startUsingItem(InteractionHand.OFF_HAND); } } @@ -286,7 +287,7 @@ private IAIState attackDummy() { worker.swing(InteractionHand.MAIN_HAND); worker.playSound(SoundEvents.PLAYER_ATTACK_SWEEP, (float) BASIC_VOLUME, (float) SoundUtils.getRandomPitch(worker.getRandom())); - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); } currentAttackDelay = RANGED_ATTACK_DELAY_BASE; @@ -316,7 +317,7 @@ protected boolean isSetup() final int weaponSlot = InventoryUtils.getFirstSlotOfItemHandlerContainingEquipment(getInventory(), ModEquipmentTypes.sword.get(), 0, building.getMaxEquipmentLevel()); if (weaponSlot != -1) { - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, weaponSlot); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, weaponSlot); } return true; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java index 1fa0bf9ddf1..038afe821a7 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkLumberjack.java @@ -17,6 +17,7 @@ import com.minecolonies.core.colony.jobs.JobLumberjack; import com.minecolonies.core.entity.ai.workers.crafting.AbstractEntityAICrafting; import com.minecolonies.core.entity.ai.workers.util.Tree; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.entity.pathfinding.PathfindingUtils; import com.minecolonies.core.entity.pathfinding.navigation.MinecoloniesAdvancedPathNavigate; import com.minecolonies.core.entity.pathfinding.pathjobs.PathJobMoveToWithPassable; @@ -39,7 +40,6 @@ import net.minecraft.world.level.pathfinder.Node; import net.minecraft.world.level.pathfinder.Path; import net.minecraft.world.phys.AABB; -import net.neoforged.neoforge.common.SpecialPlantable; import net.neoforged.neoforge.common.Tags; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -823,7 +823,7 @@ private boolean plantSapling(@NotNull final BlockPos location) if (saplingSlot != -1) { final ItemStack stack = getInventory().getStackInSlot(saplingSlot); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, saplingSlot); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, saplingSlot); if (job.getTree().isDynamicTree() && Compatibility.isDynamicTreeSapling(stack)) { diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java index 797708473af..c9409b2b50b 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/EntityAIWorkNether.java @@ -23,6 +23,7 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingNetherWorker; import com.minecolonies.core.colony.jobs.JobNetherWorker; import com.minecolonies.core.entity.ai.workers.crafting.AbstractEntityAICrafting; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.items.ItemAdventureToken; import com.minecolonies.core.util.TeleportHelper; import net.minecraft.core.BlockPos; @@ -60,8 +61,6 @@ import static com.minecolonies.api.util.constant.CitizenConstants.*; import static com.minecolonies.api.util.constant.EquipmentLevelConstants.*; import static com.minecolonies.api.util.constant.GuardConstants.*; -import static com.minecolonies.api.util.constant.NbtTagConstants.*; -import static com.minecolonies.core.colony.buildings.modules.BuildingModules.NETHERMINER_MENU; import static com.minecolonies.core.colony.buildings.modules.BuildingModules.NETHERMINER_MENU; import static com.minecolonies.core.entity.ai.workers.production.EntityAIStructureMiner.*; @@ -551,7 +550,7 @@ protected IAIState stayInNether() equipArmor(false); } - worker.getCitizenExperienceHandler().addExperience(worker.getCitizenItemHandler().applyMending(component.xp())); + worker.getCitizenExperienceHandler().addExperience(CitizenItemUtils.applyMending(worker, component.xp())); } } else if (!currStack.isEmpty()) @@ -582,7 +581,7 @@ else if (!currStack.isEmpty()) tool = findTool(block.defaultBlockState(), worker.blockPosition()); worker.setItemSlot(EquipmentSlot.MAINHAND, tool); } - worker.getCitizenExperienceHandler().addExperience(worker.getCitizenItemHandler().applyMending(xpOnDrop(block))); + worker.getCitizenExperienceHandler().addExperience(CitizenItemUtils.applyMending(worker, xpOnDrop(block))); itemDelay += TICK_DELAY; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkBeekeeper.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkBeekeeper.java index 42e9d2e5f0d..bb8acd292de 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkBeekeeper.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkBeekeeper.java @@ -16,6 +16,7 @@ import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobBeekeeper; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.tags.BlockTags; @@ -357,7 +358,7 @@ private IAIState harvestHoney() final ItemStack itemStack = worker.getMainHandItem(); if (!building.getHarvestTypes().equals(BuildingBeekeeper.HONEY) && ModEquipmentTypes.shears.get().checkIsEquipment(itemStack)) { - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); for (ItemStack stackItem : Compatibility.getCombsFromHive(hive, world, getHoneycombsPerHarvest())) { @@ -492,7 +493,7 @@ public boolean equipTool(final InteractionHand hand, final EquipmentTypeEntry to { if (getToolSlot(toolType) != -1) { - worker.getCitizenItemHandler().setHeldItem(hand, getToolSlot(toolType)); + CitizenItemUtils.setHeldItem(worker, hand, getToolSlot(toolType)); return true; } return false; @@ -527,7 +528,7 @@ public boolean equipItem(final InteractionHand hand, final ItemStack itemStack) { if (checkIfRequestForItemExistOrCreateAsync(itemStack)) { - worker.getCitizenItemHandler().setHeldItem(hand, getItemSlot(itemStack.getItem())); + CitizenItemUtils.setHeldItem(worker, hand, getItemSlot(itemStack.getItem())); return true; } return false; @@ -544,8 +545,8 @@ public boolean equipBreedItem(final InteractionHand hand) if (checkIfRequestForTagExistOrCreateAsync(ItemTags.FLOWERS, NUM_OF_FLOWERS_TO_BREED)) { ItemListModule flowersModule = building.getModuleMatching(ItemListModule.class, m -> m.getId().equals(BUILDING_FLOWER_LIST)); - worker.getCitizenItemHandler() - .setHeldItem(hand, InventoryUtils.findFirstSlotInItemHandlerWith(getInventory(), stack -> flowersModule.isItemInList(new ItemStorage(stack)))); + CitizenItemUtils + .setHeldItem(worker, hand, InventoryUtils.findFirstSlotInItemHandlerWith(getInventory(), stack -> flowersModule.isItemInList(new ItemStorage(stack)))); return true; } return false; diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java index b1f0554c3ec..a682e335406 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkComposter.java @@ -17,6 +17,7 @@ import com.minecolonies.core.colony.buildings.workerbuildings.BuildingComposter; import com.minecolonies.core.colony.jobs.JobComposter; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.tileentities.TileEntityBarrel; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; @@ -274,7 +275,7 @@ private IAIState fillBarrels() final TileEntityBarrel barrel = (TileEntityBarrel) world.getBlockEntity(currentTarget); - worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget); + CitizenItemUtils.hitBlockWithToolInHand(worker, currentTarget); barrel.addItem(worker.getItemInHand(InteractionHand.MAIN_HAND)); worker.getCitizenExperienceHandler().addExperience(BASE_XP_GAIN); this.incrementActionsDoneAndDecSaturation(); @@ -302,7 +303,7 @@ private IAIState harvestBarrels() if (world.getBlockEntity(currentTarget) instanceof TileEntityBarrel) { - worker.getCitizenItemHandler().hitBlockWithToolInHand(currentTarget); + CitizenItemUtils.hitBlockWithToolInHand(worker, currentTarget); final TileEntityBarrel te = (TileEntityBarrel) world.getBlockEntity(currentTarget); final ItemStack compost = te.retrieveCompost(getLootMultiplier(worker.getRandom())); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java index 113e59d4e7e..8d697967c2f 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFarmer.java @@ -28,6 +28,7 @@ import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobFarmer; import com.minecolonies.core.entity.ai.workers.crafting.AbstractEntityAICrafting; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.items.ItemCrop; import com.minecolonies.core.network.messages.client.CompostParticleMessage; import com.minecolonies.core.util.AdvancementUtils; @@ -51,7 +52,6 @@ import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.Vec3; import net.neoforged.neoforge.common.ItemAbilities; -import net.neoforged.neoforge.network.PacketDistributor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -588,7 +588,7 @@ private boolean hoeIfAble(BlockPos position, final FarmField farmField) equipHoe(); worker.swing(worker.getUsedItemHand()); createCorrectFarmlandForSeed(farmField.getSeed(), position); - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); worker.decreaseSaturationForContinuousAction(); worker.getCitizenColonyHandler().getColonyOrRegister().getStatisticsManager().increment(LAND_TILLED, worker.getCitizenColonyHandler().getColonyOrRegister().getDay()); @@ -700,7 +700,7 @@ private boolean tryToPlant(final FarmField farmField, BlockPos position) */ private void equipHoe() { - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, getHoeSlot()); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, getHoeSlot()); } /** diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java index 108e429c63d..3214079b48e 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkFisherman.java @@ -14,7 +14,7 @@ import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobFisherman; import com.minecolonies.core.entity.ai.workers.AbstractEntityAISkill; -import com.minecolonies.core.entity.citizen.EntityCitizen; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.entity.other.NewBobberEntity; import com.minecolonies.core.entity.pathfinding.Pathfinding; import com.minecolonies.core.entity.pathfinding.PathfindingUtils; @@ -28,7 +28,6 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.tags.ItemTags; import net.minecraft.world.InteractionHand; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.ExperienceOrb; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; @@ -607,7 +606,7 @@ private IAIState isReadyToFish() */ private void equipRod() { - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, getRodSlot()); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, getRodSlot()); } /** @@ -658,7 +657,7 @@ private void retrieveRod() worker.swing(worker.getUsedItemHand()); final int i = entityFishHook.retrieve(worker.getMainHandItem()); generateBonusLoot(); - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, i); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, i); entityFishHook = null; } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkPlanter.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkPlanter.java index 1f8aa545506..ca15bff21b8 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkPlanter.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/agriculture/EntityAIWorkPlanter.java @@ -23,6 +23,7 @@ import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobPlanter; import com.minecolonies.core.entity.ai.workers.crafting.AbstractEntityAICrafting; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.world.item.ItemStack; @@ -223,7 +224,7 @@ private IAIState workField() if (handlerResult.equals(ActionHandlerResult.FINISHED)) { - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); if (activeModuleResult.getAction().increasesActionCount()) { @@ -311,13 +312,13 @@ private ActionHandlerResult handlePlantingAction() } final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(worker.getItemHandlerCitizen(), currentStack.getItem()); - worker.getCitizenItemHandler().setMainHeldItem(slot); + CitizenItemUtils.setMainHeldItem(worker, slot); BlockState blockState = planterModule.getPlantingBlockState(world, activeModuleResult.getWorkingPosition(), BlockUtils.getBlockStateFromStack(currentStack)); if (world.setBlockAndUpdate(activeModuleResult.getActionPosition(), blockState)) { InventoryUtils.reduceStackInItemHandler(worker.getItemHandlerCitizen(), currentStack); - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); return ActionHandlerResult.FINISHED; } @@ -371,7 +372,7 @@ private ActionHandlerResult handleMiningAction(boolean isHarvest) boolean mineResult = mineBlock(activeModuleResult.getActionPosition()); if (mineResult) { - worker.getCitizenItemHandler().pickupItems(); + CitizenItemUtils.pickupItems(worker); if (isHarvest) { diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/AbstractEntityAIHerder.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/AbstractEntityAIHerder.java index 45cca44b1e3..666fb9303f9 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/AbstractEntityAIHerder.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/AbstractEntityAIHerder.java @@ -13,6 +13,7 @@ import com.minecolonies.core.colony.buildings.modules.AnimalHerdingModule; import com.minecolonies.core.colony.jobs.AbstractJob; import com.minecolonies.core.entity.ai.workers.AbstractEntityAIInteract; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.InteractionHand; @@ -410,7 +411,7 @@ protected IAIState breedAnimals() { if (current_module == null) { - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); return DECIDE; } @@ -424,7 +425,7 @@ protected IAIState breedAnimals() if (breedables.size() < 2) { - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); breedTimeOut = TICKS_SECOND * 60; return DECIDE; } @@ -448,14 +449,14 @@ protected IAIState breedAnimals() if (animalTwo == null) { - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); breedTimeOut = TICKS_SECOND * 20; return DECIDE; } if (!equipItem(InteractionHand.MAIN_HAND, current_module.getBreedingItems())) { - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); return START_WORKING; } @@ -469,7 +470,7 @@ protected IAIState breedAnimals() } breedTimeOut = TICKS_SECOND * 60; - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); return IDLE; } @@ -547,7 +548,7 @@ protected IAIState feedAnimal() worker.getCitizenExperienceHandler().addExperience(XP_PER_ACTION); worker.level().broadcastEntityEvent(toFeed, (byte) 18); toFeed.playSound(SoundEvents.GENERIC_EAT, 1.0F, 1.0F); - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); fedRecently.put(toFeed.getUUID(), worker.level().getGameTime()); return DECIDE; @@ -694,7 +695,7 @@ public boolean equipTool(final InteractionHand hand, final EquipmentTypeEntry to { if (getToolSlot(toolType) != -1) { - worker.getCitizenItemHandler().setHeldItem(hand, getToolSlot(toolType)); + CitizenItemUtils.setHeldItem(worker, hand, getToolSlot(toolType)); return true; } return false; @@ -731,7 +732,7 @@ public boolean equipItem(final InteractionHand hand, final List itemS { if (checkIfRequestForItemExistOrCreateAsync(itemStack)) { - worker.getCitizenItemHandler().setHeldItem(hand, getItemSlot(itemStack.getItem())); + CitizenItemUtils.setHeldItem(worker, hand, getItemSlot(itemStack.getItem())); return true; } } @@ -762,7 +763,7 @@ protected void butcherAnimal(@Nullable final Animal animal) worker.swing(InteractionHand.MAIN_HAND); final DamageSource ds = animal.level().damageSources().playerAttack(getFakePlayer()); animal.hurt(ds, (float) getButcheringAttackDamage()); - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkChickenHerder.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkChickenHerder.java index e0f58079308..38c40fe456c 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkChickenHerder.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkChickenHerder.java @@ -7,6 +7,7 @@ import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingChickenHerder; import com.minecolonies.core.colony.jobs.JobChickenHerder; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.animal.Animal; @@ -66,7 +67,7 @@ protected void butcherAnimal(@Nullable final Animal animal) if (worker.getRandom().nextInt(1 + (ONE_HUNDRED_PERCENT - getSecondarySkillLevel()) / 5) <= 1) { animal.hurt(world.damageSources().source(DamageSourceKeys.DEFAULT, worker), (float) getButcheringAttackDamage()); - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); } } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkCowboy.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkCowboy.java index b8f5373e042..c820bf74628 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkCowboy.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkCowboy.java @@ -9,6 +9,7 @@ import com.minecolonies.api.util.constant.Constants; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingCowboy; import com.minecolonies.core.colony.jobs.JobCowboy; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.InteractionHand; @@ -170,7 +171,7 @@ private IAIState milkCows() if (InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), building.getMilkOutputItem())) { building.getFirstModuleOccurance(BuildingCowboy.HerdingModule.class).onMilked(); - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); equipItem(InteractionHand.MAIN_HAND, Collections.singletonList(building.getMilkOutputItem())); InventoryUtils.tryRemoveStackFromItemHandler(worker.getInventoryCitizen(), building.getMilkInputItem()); } @@ -224,7 +225,7 @@ private IAIState milkMooshrooms() if (InventoryUtils.addItemStackToItemHandler(worker.getInventoryCitizen(), fakePlayer.getMainHandItem())) { building.getFirstModuleOccurance(BuildingCowboy.HerdingModule.class).onStewed(); - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); equipItem(InteractionHand.MAIN_HAND, Collections.singletonList(fakePlayer.getMainHandItem())); InventoryUtils.tryRemoveStackFromItemHandler(worker.getInventoryCitizen(), new ItemStack(Items.BOWL)); } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkRabbitHerder.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkRabbitHerder.java index 7af3563e117..4b9c7669eba 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkRabbitHerder.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkRabbitHerder.java @@ -3,6 +3,7 @@ import com.minecolonies.api.util.ItemStackUtils; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingRabbitHutch; import com.minecolonies.core.colony.jobs.JobRabbitHerder; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.world.InteractionHand; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.animal.Animal; @@ -61,7 +62,7 @@ protected void butcherAnimal(@Nullable final Animal animal) { final DamageSource ds = animal.level().damageSources().playerAttack(getFakePlayer()); animal.hurt(ds, (float) getButcheringAttackDamage()); - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); } } } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkShepherd.java b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkShepherd.java index f5842de8ae3..4b017430700 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkShepherd.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/production/herders/EntityAIWorkShepherd.java @@ -8,6 +8,7 @@ import com.minecolonies.api.util.Utils; import com.minecolonies.core.colony.buildings.workerbuildings.BuildingShepherd; import com.minecolonies.core.colony.jobs.JobShepherd; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.network.messages.client.LocalizedParticleEffectMessage; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.InteractionHand; @@ -149,7 +150,7 @@ private IAIState shearSheep() new LocalizedParticleEffectMessage(new ItemStack(ITEM_BY_DYE.get(sheep.getColor())), sheep.getOnPos().above()).sendToTrackingEntity(worker); dyeSheepChance(sheep); - worker.getCitizenItemHandler().damageItemInHand(InteractionHand.MAIN_HAND, 1); + CitizenItemUtils.damageItemInHand(worker, InteractionHand.MAIN_HAND, 1); worker.getCitizenExperienceHandler().addExperience(XP_PER_ACTION); incrementActionsDoneAndDecSaturation(); diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java index 71f92cbcae5..c9e902e5ca6 100755 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkDeliveryman.java @@ -13,6 +13,7 @@ import com.minecolonies.api.entity.ai.statemachine.states.IAIState; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; import com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.tileentities.TileEntityColonyBuilding; import com.minecolonies.core.tileentities.TileEntityRack; import com.minecolonies.api.util.InventoryUtils; @@ -252,7 +253,7 @@ private boolean pickupFromBuilding(@NotNull final IBuilding building) // The worker gets a little bit of exp for every itemstack he grabs. worker.getCitizenExperienceHandler().addExperience(0.01D); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, SLOT_HAND); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, SLOT_HAND); return false; } @@ -303,7 +304,7 @@ private IAIState dump() } warehouse.getTileEntity().dumpInventoryIntoWareHouse(worker.getInventoryCitizen()); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, SLOT_HAND); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, SLOT_HAND); return START_WORKING; } @@ -449,7 +450,7 @@ private IAIState deliver() // This can only happen if the dman's inventory was completely empty. // Let the retry-system handle this case. worker.decreaseSaturationForContinuousAction(); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, SLOT_HAND); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, SLOT_HAND); job.finishRequest(false); // No need to go dumping in this case. @@ -458,7 +459,7 @@ private IAIState deliver() worker.getCitizenExperienceHandler().addExperience(1.5D); worker.decreaseSaturationForContinuousAction(); - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, SLOT_HAND); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, SLOT_HAND); job.finishRequest(true); return success ? START_WORKING : DUMPING; } diff --git a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java index 68a3c710132..c1ddfec32fe 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java +++ b/src/main/java/com/minecolonies/core/entity/ai/workers/service/EntityAIWorkUndertaker.java @@ -9,6 +9,7 @@ import com.minecolonies.api.entity.citizen.Skill; import com.minecolonies.api.entity.citizen.VisibleCitizenStatus; import com.minecolonies.api.equipment.ModEquipmentTypes; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.tileentities.TileEntityGrave; import com.minecolonies.api.util.InventoryUtils; import com.minecolonies.api.util.MessageUtils; @@ -448,7 +449,7 @@ private IAIState buryCitizen() if (effortCounter < EFFORT_BURY) { equipShovel(); - worker.getCitizenItemHandler().hitBlockWithToolInHand(burialPos.getA(), false); + CitizenItemUtils.hitBlockWithToolInHand(worker, burialPos.getA(), false); effortCounter += getPrimarySkillLevel(); return getState(); } @@ -487,7 +488,7 @@ protected boolean wantInventoryDumped() */ private void equipShovel() { - worker.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, getShovelSlot()); + CitizenItemUtils.setHeldItem(worker, InteractionHand.MAIN_HAND, getShovelSlot()); } /** @@ -495,7 +496,7 @@ private void equipShovel() */ private void unequip() { - worker.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(worker); } /** diff --git a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java index 743449e2718..2203000b43f 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/EntityCitizen.java @@ -62,6 +62,7 @@ import com.minecolonies.core.network.messages.client.colony.ColonyViewCitizenViewMessage; import com.minecolonies.core.network.messages.client.colony.PlaySoundForCitizenMessage; import com.minecolonies.core.network.messages.server.colony.OpenInventoryMessage; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import com.minecolonies.core.util.TeleportHelper; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; @@ -84,7 +85,6 @@ import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.*; -import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Inventory; @@ -156,10 +156,7 @@ public class EntityCitizen extends AbstractEntityCitizen implements IThreatTable * The citizen experience handler. */ private ICitizenExperienceHandler citizenExperienceHandler; - /** - * The citizen item handler. - */ - private ICitizenItemHandler citizenItemHandler; + /** * The citizen inv handler. */ @@ -251,7 +248,6 @@ public EntityCitizen(final EntityType type, final Level { super(type, world); this.citizenExperienceHandler = new CitizenExperienceHandler(this); - this.citizenItemHandler = new CitizenItemHandler(this); this.citizenInventoryHandler = new CitizenInventoryHandler(this); this.citizenColonyHandler = new CitizenColonyHandler(this); this.citizenJobHandler = new CitizenJobHandler(this); @@ -749,7 +745,7 @@ private boolean onServerUpdateHandlers() { // Every 20 ticks citizenExperienceHandler.gatherXp(); - citizenItemHandler.pickupItems(); + CitizenItemUtils.pickupItems(this); citizenData.setLastPosition(blockPosition()); onLivingSoundUpdate(); @@ -1160,17 +1156,6 @@ public ICitizenExperienceHandler getCitizenExperienceHandler() return citizenExperienceHandler; } - /** - * The Handler for all item related methods. - * - * @return the instance of the handler. - */ - @Override - public ICitizenItemHandler getCitizenItemHandler() - { - return citizenItemHandler; - } - /** * The Handler for all inventory related methods. * @@ -1270,12 +1255,6 @@ public void setCitizenJobHandler(final ICitizenJobHandler citizenJobHandler) this.citizenJobHandler = citizenJobHandler; } - @Override - public void setCitizenItemHandler(final ICitizenItemHandler citizenItemHandler) - { - this.citizenItemHandler = citizenItemHandler; - } - @Override public void setCitizenExperienceHandler(final ICitizenExperienceHandler citizenExperienceHandler) { @@ -1461,7 +1440,7 @@ && getHealth() < ((int) getMaxHealth() * 0.2D)) setHealth(getHealth() - Math.max(GUARD_BLOCK_DAMAGE, blockDamage)); result = true; } - citizenItemHandler.damageItemInHand(this.getUsedItemHand(), (int) (blockedDamage * GUARD_BLOCK_DAMAGE)); + CitizenItemUtils.damageItemInHand(this, this.getUsedItemHand(), (int) (blockedDamage * GUARD_BLOCK_DAMAGE)); } } } @@ -1484,7 +1463,7 @@ && getHealth() < ((int) getMaxHealth() * 0.2D)) if (!level().isClientSide) { - citizenItemHandler.updateArmorDamage(damageInc); + CitizenItemUtils.updateArmorDamage(this, damageInc); if (citizenData != null) { getCitizenData().getCitizenHappinessHandler().addModifier(new ExpirationBasedHappinessModifier(DAMAGE, 2.0, new StaticHappinessSupplier(0.0), 1)); @@ -1697,7 +1676,7 @@ protected void dropEquipment() final ItemStack itemstack = getCitizenData().getInventory().getStackInSlot(i); if (ItemStackUtils.getSize(itemstack) > 0) { - citizenItemHandler.entityDropItem(itemstack); + CitizenItemUtils.entityDropItem(this, itemstack); } } } diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenExperienceHandler.java b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenExperienceHandler.java index 78c789b45d5..1755096faff 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenExperienceHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenExperienceHandler.java @@ -8,6 +8,7 @@ import com.minecolonies.api.util.CompatibilityUtils; import com.minecolonies.api.util.WorldUtil; import com.minecolonies.core.colony.buildings.modules.WorkerBuildingModule; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.ExperienceOrb; @@ -190,7 +191,7 @@ public void gatherXp() if (d1 < 1.0D) { double localXp = orb.getValue(); - localXp = citizen.getCitizenItemHandler().applyMending(localXp); + localXp = CitizenItemUtils.applyMending(citizen, localXp); addExperience(localXp); orb.remove(Entity.RemovalReason.DISCARDED); counterMovedXp = 0; @@ -198,7 +199,7 @@ public void gatherXp() else if (counterMovedXp > MAX_XP_PICKUP_ATTEMPTS) { double localXp = orb.getValue(); - localXp = citizen.getCitizenItemHandler().applyMending(localXp); + localXp = CitizenItemUtils.applyMending(citizen, localXp); addExperience(localXp); orb.remove(Entity.RemovalReason.DISCARDED); counterMovedXp = 0; diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenSleepHandler.java b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenSleepHandler.java index eef56425549..b513e4d6678 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenSleepHandler.java +++ b/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenSleepHandler.java @@ -10,6 +10,7 @@ import com.minecolonies.core.colony.interactionhandling.SimpleNotificationInteraction; import com.minecolonies.core.colony.interactionhandling.StandardInteraction; import com.minecolonies.core.colony.jobs.JobMiner; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.network.chat.Component; @@ -120,7 +121,7 @@ public boolean trySleep(final BlockPos bedLocation) citizen.hasImpulse = true; //Remove item while citizen is asleep. - citizen.getCitizenItemHandler().removeHeldItem(); + CitizenItemUtils.removeHeldItem(citizen); setIsAsleep(true); diff --git a/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java b/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java index 5e373515980..3252372be0c 100644 --- a/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java +++ b/src/main/java/com/minecolonies/core/entity/visitor/VisitorCitizen.java @@ -27,6 +27,7 @@ import com.minecolonies.core.entity.pathfinding.proxy.EntityCitizenWalkToProxy; import com.minecolonies.core.network.messages.client.ItemParticleEffectMessage; import com.minecolonies.core.network.messages.server.colony.OpenInventoryMessage; +import com.minecolonies.core.util.citizenutils.CitizenItemUtils; import net.minecraft.core.BlockPos; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.syncher.EntityDataAccessor; @@ -86,10 +87,6 @@ public class VisitorCitizen extends AbstractEntityCitizen @Nullable private ICitizenData citizenData; - /** - * The citizen item handler. - */ - private ICitizenItemHandler citizenItemHandler; /** * The citizen inv handler. */ @@ -128,7 +125,6 @@ public class VisitorCitizen extends AbstractEntityCitizen public VisitorCitizen(final EntityType type, final Level world) { super(type, world); - this.citizenItemHandler = new CitizenItemHandler(this); this.citizenInventoryHandler = new CitizenInventoryHandler(this); this.citizenColonyHandler = new VisitorColonyHandler(this); this.citizenJobHandler = new CitizenJobHandler(this); @@ -343,12 +339,6 @@ public ICitizenExperienceHandler getCitizenExperienceHandler() return citizenExperienceHandler; } - @Override - public ICitizenItemHandler getCitizenItemHandler() - { - return citizenItemHandler; - } - @Override public ICitizenInventoryHandler getCitizenInventoryHandler() { @@ -415,12 +405,6 @@ public void setCitizenJobHandler(final ICitizenJobHandler citizenJobHandler) this.citizenJobHandler = citizenJobHandler; } - @Override - public void setCitizenItemHandler(final ICitizenItemHandler citizenItemHandler) - { - this.citizenItemHandler = citizenItemHandler; - } - @Override public void setCitizenExperienceHandler(final ICitizenExperienceHandler citizenExperienceHandler) { @@ -635,7 +619,7 @@ protected void dropEquipment() final ItemStack itemstack = getCitizenData().getInventory().getStackInSlot(i); if (ItemStackUtils.getSize(itemstack) > 0) { - citizenItemHandler.entityDropItem(itemstack); + CitizenItemUtils.entityDropItem(this, itemstack); } } } diff --git a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenItemHandler.java b/src/main/java/com/minecolonies/core/util/citizenutils/CitizenItemUtils.java similarity index 88% rename from src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenItemHandler.java rename to src/main/java/com/minecolonies/core/util/citizenutils/CitizenItemUtils.java index b0c8a2938a8..03bc046eef0 100755 --- a/src/main/java/com/minecolonies/core/entity/citizen/citizenhandlers/CitizenItemHandler.java +++ b/src/main/java/com/minecolonies/core/util/citizenutils/CitizenItemUtils.java @@ -1,7 +1,6 @@ -package com.minecolonies.core.entity.citizen.citizenhandlers; +package com.minecolonies.core.util.citizenutils; import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; -import com.minecolonies.api.entity.citizen.citizenhandlers.ICitizenItemHandler; import com.minecolonies.api.util.*; import com.minecolonies.core.network.messages.client.BlockParticleEffectMessage; import net.minecraft.core.BlockPos; @@ -19,7 +18,6 @@ import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; -import net.neoforged.neoforge.network.PacketDistributor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,30 +31,14 @@ * Handles the citizens interaction with an item with the world. */ @SuppressWarnings("PMD.ExcessiveImports") -public class CitizenItemHandler implements ICitizenItemHandler +public class CitizenItemUtils { - /** - * The citizen assigned to this manager. - */ - private final AbstractEntityCitizen citizen; - - /** - * Constructor for the experience handler. - * - * @param citizen the citizen owning the handler. - */ - public CitizenItemHandler(final AbstractEntityCitizen citizen) - { - this.citizen = citizen; - } - /** * Citizen will try to pick up a certain item. * * @param itemEntity the item he wants to pickup. */ - @Override - public void tryPickupItemEntity(@NotNull final ItemEntity itemEntity) + public static void tryPickupItemEntity(@NotNull final AbstractEntityCitizen citizen, @NotNull final ItemEntity itemEntity) { if (!CompatibilityUtils.getWorldFromCitizen(citizen).isClientSide) { @@ -107,8 +89,7 @@ public void tryPickupItemEntity(@NotNull final ItemEntity itemEntity) /** * Removes the currently held item. */ - @Override - public void removeHeldItem() + public static void removeHeldItem(AbstractEntityCitizen citizen) { citizen.setItemSlot(EquipmentSlot.MAINHAND, ItemStackUtils.EMPTY); } @@ -119,8 +100,7 @@ public void removeHeldItem() * @param hand what hand we're setting * @param slot from the inventory slot. */ - @Override - public void setHeldItem(final InteractionHand hand, final int slot) + public static void setHeldItem(@NotNull final AbstractEntityCitizen citizen, final InteractionHand hand, final int slot) { citizen.getCitizenData().getInventory().setHeldItem(hand, slot); if (hand.equals(InteractionHand.MAIN_HAND)) @@ -138,8 +118,7 @@ else if (hand.equals(InteractionHand.OFF_HAND)) * * @param slot from the inventory slot. */ - @Override - public void setMainHeldItem(final int slot) + public static void setMainHeldItem(@NotNull final AbstractEntityCitizen citizen, final int slot) { citizen.getCitizenData().getInventory().setHeldItem(InteractionHand.MAIN_HAND, slot); citizen.setItemSlot(EquipmentSlot.MAINHAND, citizen.getCitizenData().getInventory().getStackInSlot(slot)); @@ -152,14 +131,13 @@ public void setMainHeldItem(final int slot) * * @param blockPos Block position. */ - @Override - public void hitBlockWithToolInHand(@Nullable final BlockPos blockPos) + public static void hitBlockWithToolInHand(@NotNull final AbstractEntityCitizen citizen, @Nullable final BlockPos blockPos) { if (blockPos == null) { return; } - hitBlockWithToolInHand(blockPos, false); + hitBlockWithToolInHand(citizen, blockPos, false); } /** @@ -170,8 +148,8 @@ public void hitBlockWithToolInHand(@Nullable final BlockPos blockPos) * @param blockPos Block position. * @param breakBlock if we want to break this block. */ - @Override - public void hitBlockWithToolInHand(@Nullable final BlockPos blockPos, final boolean breakBlock) + + public static void hitBlockWithToolInHand(@NotNull final AbstractEntityCitizen citizen, @Nullable final BlockPos blockPos, final boolean breakBlock) { if (blockPos == null) { @@ -199,7 +177,7 @@ public void hitBlockWithToolInHand(@Nullable final BlockPos blockPos, final bool block.getSoundType(blockState, CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, citizen).getPitch()); WorldUtil.removeBlock(CompatibilityUtils.getWorldFromCitizen(citizen), blockPos, false); - damageItemInHand(citizen.getUsedItemHand(), 1); + damageItemInHand(citizen, citizen.getUsedItemHand(), 1); } else { @@ -225,8 +203,7 @@ public void hitBlockWithToolInHand(@Nullable final BlockPos blockPos, final bool * * @param damage amount of damage. */ - @Override - public void damageItemInHand(final InteractionHand hand, final int damage) + public static void damageItemInHand(@NotNull final AbstractEntityCitizen citizen, final InteractionHand hand, final int damage) { final ItemStack heldItem = citizen.getCitizenData().getInventory().getHeldItem(hand); //If we hit with bare hands, ignore @@ -267,8 +244,7 @@ public void damageItemInHand(final InteractionHand hand, final int damage) /** * Pick up all items in a range around the citizen. */ - @Override - public void pickupItems() + public static void pickupItems(AbstractEntityCitizen citizen) { for (final ItemEntity item : CompatibilityUtils.getWorldFromCitizen(citizen).getEntitiesOfClass(ItemEntity.class, new AABB(citizen.blockPosition()) @@ -277,7 +253,7 @@ public void pickupItems() { if (item != null && item.isAlive()) { - tryPickupItemEntity(item); + tryPickupItemEntity(citizen, item); } } } @@ -289,14 +265,13 @@ public void pickupItems() * * @param blockPos Block position. */ - @Override - public void breakBlockWithToolInHand(@Nullable final BlockPos blockPos) + public static void breakBlockWithToolInHand(@NotNull final AbstractEntityCitizen citizen, @Nullable final BlockPos blockPos) { if (blockPos == null) { return; } - hitBlockWithToolInHand(blockPos, true); + hitBlockWithToolInHand(citizen, blockPos, true); } /** @@ -305,8 +280,7 @@ public void breakBlockWithToolInHand(@Nullable final BlockPos blockPos) * @param itemstack to drop. * @return the dropped item. */ - @Override - public ItemEntity entityDropItem(@NotNull final ItemStack itemstack) + public static ItemEntity entityDropItem(@NotNull final AbstractEntityCitizen citizen, @NotNull final ItemStack itemstack) { return citizen.spawnAtLocation(itemstack, 0.0F); } @@ -316,8 +290,7 @@ public ItemEntity entityDropItem(@NotNull final ItemStack itemstack) * * @param damage damage dealt. */ - @Override - public void updateArmorDamage(final double damage) + public static void updateArmorDamage(@NotNull final AbstractEntityCitizen citizen, final double damage) { if (citizen.getCitizenColonyHandler().getColonyOrRegister().getResearchManager().getResearchEffects().getEffectStrength(ARMOR_DURABILITY) > 0) { @@ -345,8 +318,7 @@ public void updateArmorDamage(final double damage) } } - @Override - public double applyMending(final double xp) + public static double applyMending(@NotNull final AbstractEntityCitizen citizen, final double xp) { double localXp = xp;