diff --git a/src/main/java/com/minecolonies/api/util/LookHandler.java b/src/main/java/com/minecolonies/api/util/LookHandler.java index cff3f5b0765..02eff2ec1da 100644 --- a/src/main/java/com/minecolonies/api/util/LookHandler.java +++ b/src/main/java/com/minecolonies/api/util/LookHandler.java @@ -1,6 +1,7 @@ package com.minecolonies.api.util; import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.control.LookControl; @@ -8,6 +9,12 @@ public class LookHandler extends LookControl { private boolean doneNavigating = true; + /** + * Remembers the entity to look at for a short while + */ + private Entity lookingAt = null; + private int lookAtTimer = 0; + public LookHandler(final Mob entity) { super(entity); @@ -21,6 +28,15 @@ public void tick() doneNavigating = this.mob.getNavigation().isDone(); } + if (lookingAt != null && lookAtTimer-- > 0) + { + super.setLookAt(lookingAt); + if (lookAtTimer == 0) + { + lookingAt = null; + } + } + if (this.resetXRotOnTick()) { this.mob.setXRot(0.0F); @@ -63,4 +79,20 @@ public void setLookAtCooldown(final int cooldown) { lookAtCooldown = cooldown; } + + @Override + public void setLookAt(Entity entity) + { + super.setLookAt(entity); + lookAtTimer = 20 * 5; + lookingAt = entity; + } + + @Override + public void setLookAt(Entity entity, float turnY, float turnX) + { + super.setLookAt(entity, turnY, turnX); + lookAtTimer = 20 * 5; + lookingAt = entity; + } } \ No newline at end of file diff --git a/src/main/java/com/minecolonies/core/client/render/RenderBipedCitizen.java b/src/main/java/com/minecolonies/core/client/render/RenderBipedCitizen.java index d1e766a8a86..83420130d75 100755 --- a/src/main/java/com/minecolonies/core/client/render/RenderBipedCitizen.java +++ b/src/main/java/com/minecolonies/core/client/render/RenderBipedCitizen.java @@ -7,24 +7,20 @@ import com.minecolonies.api.entity.citizen.AbstractEntityCitizen; import com.minecolonies.apiimp.initializer.ModModelTypeInitializer; import com.minecolonies.core.client.render.worldevent.RenderTypes; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.systems.RenderSystem; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelLayers; import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.MobRenderer; -import net.minecraft.client.renderer.entity.layers.CustomHeadLayer; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; -import net.minecraft.client.model.HumanoidModel; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.UseAnim; -import net.minecraft.world.entity.HumanoidArm; -import net.minecraft.resources.ResourceLocation; - -import org.joml.Matrix4f; import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.InteractionHand; import org.jetbrains.annotations.NotNull; +import org.joml.Matrix4f; /** * Renderer for the citizens. @@ -61,12 +57,8 @@ public void render( final CitizenModel citizenModel = model; - final ItemStack mainHandStack = citizen.getMainHandItem(); - final ItemStack offHandStack = citizen.getOffhandItem(); - final HumanoidModel.ArmPose armPoseMainHand = getArmPoseFrom(citizen, mainHandStack); - final HumanoidModel.ArmPose armPoseOffHand = getArmPoseFrom(citizen, offHandStack); - - updateArmPose(citizen, citizenModel, armPoseMainHand, armPoseOffHand); + citizenModel.rightArmPose = RenderUtils.getArmPose(citizen, InteractionHand.MAIN_HAND); + citizenModel.leftArmPose = RenderUtils.getArmPose(citizen, InteractionHand.OFF_HAND); if (isItGhostTime) { @@ -140,47 +132,6 @@ protected void renderNameTag( } } - private HumanoidModel.ArmPose getArmPoseFrom(@NotNull final AbstractEntityCitizen citizen, final ItemStack mainHandStack) - { - final UseAnim enumActionMainHand; - HumanoidModel.ArmPose pose = HumanoidModel.ArmPose.EMPTY; - if (!mainHandStack.isEmpty()) - { - pose = HumanoidModel.ArmPose.ITEM; - if (citizen.getUseItemRemainingTicks() > 0) - { - enumActionMainHand = mainHandStack.getUseAnimation(); - if (enumActionMainHand == UseAnim.BLOCK) - { - pose = HumanoidModel.ArmPose.BLOCK; - } - else if (enumActionMainHand == UseAnim.BOW) - { - pose = HumanoidModel.ArmPose.BOW_AND_ARROW; - } - } - } - return pose; - } - - private void updateArmPose( - @NotNull final AbstractEntityCitizen citizen, - final HumanoidModel citizenModel, - final HumanoidModel.ArmPose armPoseMainHand, - final HumanoidModel.ArmPose armPoseOffHand) - { - if (citizen.getMainArm() == HumanoidArm.RIGHT) - { - citizenModel.rightArmPose = armPoseMainHand; - citizenModel.leftArmPose = armPoseOffHand; - } - else - { - citizenModel.rightArmPose = armPoseOffHand; - citizenModel.leftArmPose = armPoseMainHand; - } - } - @NotNull @Override public ResourceLocation getTextureLocation(final AbstractEntityCitizen entity) diff --git a/src/main/java/com/minecolonies/core/client/render/RenderUtils.java b/src/main/java/com/minecolonies/core/client/render/RenderUtils.java new file mode 100644 index 00000000000..058a46d3176 --- /dev/null +++ b/src/main/java/com/minecolonies/core/client/render/RenderUtils.java @@ -0,0 +1,85 @@ +package com.minecolonies.core.client.render; + +import net.minecraft.client.model.HumanoidModel; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.item.CrossbowItem; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.UseAnim; + +public class RenderUtils +{ + /** + * Arm pose helper, take from PlayerRenderer#getArmPose + * + * @param entity + * @param hand + * @return + */ + public static HumanoidModel.ArmPose getArmPose(Mob entity, InteractionHand hand) + { + if (entity.isLeftHanded()) + { + hand = hand == InteractionHand.MAIN_HAND ? InteractionHand.OFF_HAND : InteractionHand.MAIN_HAND; + } + + ItemStack itemstack = entity.getItemInHand(hand); + if (itemstack.isEmpty()) + { + return HumanoidModel.ArmPose.EMPTY; + } + else + { + if (entity.getUsedItemHand() == hand && entity.getUseItemRemainingTicks() > 0) + { + UseAnim useanim = itemstack.getUseAnimation(); + if (useanim == UseAnim.BLOCK) + { + return HumanoidModel.ArmPose.BLOCK; + } + + if (useanim == UseAnim.BOW) + { + return HumanoidModel.ArmPose.BOW_AND_ARROW; + } + + if (useanim == UseAnim.SPEAR) + { + return HumanoidModel.ArmPose.THROW_SPEAR; + } + + if (useanim == UseAnim.CROSSBOW && hand == entity.getUsedItemHand()) + { + return HumanoidModel.ArmPose.CROSSBOW_CHARGE; + } + + if (useanim == UseAnim.SPYGLASS) + { + return HumanoidModel.ArmPose.SPYGLASS; + } + + if (useanim == UseAnim.TOOT_HORN) + { + return HumanoidModel.ArmPose.TOOT_HORN; + } + + if (useanim == UseAnim.BRUSH) + { + return HumanoidModel.ArmPose.BRUSH; + } + } + else if (!entity.swinging && itemstack.getItem() instanceof CrossbowItem && CrossbowItem.isCharged(itemstack)) + { + return HumanoidModel.ArmPose.CROSSBOW_HOLD; + } + + HumanoidModel.ArmPose forgeArmPose = net.minecraftforge.client.extensions.common.IClientItemExtensions.of(itemstack).getArmPose(entity, hand, itemstack); + if (forgeArmPose != null) + { + return forgeArmPose; + } + + return HumanoidModel.ArmPose.ITEM; + } + } +} diff --git a/src/main/java/com/minecolonies/core/client/render/mobs/amazon/AbstractRendererAmazon.java b/src/main/java/com/minecolonies/core/client/render/mobs/amazon/AbstractRendererAmazon.java index 66fb72cc998..aa71b94ed4a 100755 --- a/src/main/java/com/minecolonies/core/client/render/mobs/amazon/AbstractRendererAmazon.java +++ b/src/main/java/com/minecolonies/core/client/render/mobs/amazon/AbstractRendererAmazon.java @@ -1,12 +1,16 @@ package com.minecolonies.core.client.render.mobs.amazon; import com.minecolonies.api.entity.mobs.amazons.AbstractEntityAmazon; +import com.minecolonies.core.client.render.RenderUtils; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelLayers; -import net.minecraft.client.renderer.entity.HumanoidMobRenderer; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.HumanoidMobRenderer; import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; -import net.minecraft.client.model.HumanoidModel; +import net.minecraft.world.InteractionHand; /** * Abstract for rendering amazons. @@ -19,4 +23,12 @@ public AbstractRendererAmazon(final EntityRendererProvider.Context context, fina this.addLayer(new ItemInHandLayer<>(this, context.getItemInHandRenderer())); this.addLayer(new HumanoidArmorLayer<>(this, new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)), context.getModelManager())); } + + @Override + public void render(T raider, float p_115456_, float p_115457_, PoseStack p_115458_, MultiBufferSource p_115459_, int p_115460_) + { + model.rightArmPose = RenderUtils.getArmPose(raider, InteractionHand.MAIN_HAND); + model.leftArmPose = RenderUtils.getArmPose(raider, InteractionHand.OFF_HAND); + super.render(raider, p_115456_, p_115457_, p_115458_, p_115459_, p_115460_); + } } \ No newline at end of file diff --git a/src/main/java/com/minecolonies/core/client/render/mobs/barbarians/AbstractRendererBarbarian.java b/src/main/java/com/minecolonies/core/client/render/mobs/barbarians/AbstractRendererBarbarian.java index 42bd17f5db5..56f21712376 100755 --- a/src/main/java/com/minecolonies/core/client/render/mobs/barbarians/AbstractRendererBarbarian.java +++ b/src/main/java/com/minecolonies/core/client/render/mobs/barbarians/AbstractRendererBarbarian.java @@ -1,12 +1,16 @@ package com.minecolonies.core.client.render.mobs.barbarians; import com.minecolonies.api.entity.mobs.barbarians.AbstractEntityBarbarian; +import com.minecolonies.core.client.render.RenderUtils; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelLayers; -import net.minecraft.client.renderer.entity.HumanoidMobRenderer; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.HumanoidMobRenderer; import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; -import net.minecraft.client.model.HumanoidModel; +import net.minecraft.world.InteractionHand; /** * Abstract for rendering Barbarians. @@ -17,6 +21,17 @@ public AbstractRendererBarbarian(final EntityRendererProvider.Context context, f { super(context, modelBipedIn, shadowSize); this.addLayer(new ItemInHandLayer<>(this, context.getItemInHandRenderer())); - this.addLayer(new HumanoidArmorLayer<>(this, new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)), context.getModelManager())); + this.addLayer(new HumanoidArmorLayer<>(this, + new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), + new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)), + context.getModelManager())); + } + + @Override + public void render(T raider, float p_115456_, float p_115457_, PoseStack p_115458_, MultiBufferSource p_115459_, int p_115460_) + { + model.rightArmPose = RenderUtils.getArmPose(raider, InteractionHand.MAIN_HAND); + model.leftArmPose = RenderUtils.getArmPose(raider, InteractionHand.OFF_HAND); + super.render(raider, p_115456_, p_115457_, p_115458_, p_115459_, p_115460_); } } \ No newline at end of file diff --git a/src/main/java/com/minecolonies/core/client/render/mobs/drownedpirates/AbstractRendererDrownedPirate.java b/src/main/java/com/minecolonies/core/client/render/mobs/drownedpirates/AbstractRendererDrownedPirate.java index c914dd9827d..3f33c11f369 100755 --- a/src/main/java/com/minecolonies/core/client/render/mobs/drownedpirates/AbstractRendererDrownedPirate.java +++ b/src/main/java/com/minecolonies/core/client/render/mobs/drownedpirates/AbstractRendererDrownedPirate.java @@ -1,13 +1,16 @@ package com.minecolonies.core.client.render.mobs.drownedpirates; import com.minecolonies.api.entity.mobs.drownedpirate.AbstractDrownedEntityPirate; -import com.minecolonies.api.entity.mobs.pirates.AbstractEntityPirate; +import com.minecolonies.core.client.render.RenderUtils; +import com.mojang.blaze3d.vertex.PoseStack; import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelLayers; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.HumanoidMobRenderer; import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; +import net.minecraft.world.InteractionHand; /** * Abstract for rendering Pirates. @@ -20,4 +23,12 @@ public AbstractRendererDrownedPirate(final EntityRendererProvider.Context contex this.addLayer(new ItemInHandLayer<>(this, context.getItemInHandRenderer())); this.addLayer(new HumanoidArmorLayer<>(this, new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)), context.getModelManager())); } + + @Override + public void render(T raider, float p_115456_, float p_115457_, PoseStack p_115458_, MultiBufferSource p_115459_, int p_115460_) + { + model.rightArmPose = RenderUtils.getArmPose(raider, InteractionHand.MAIN_HAND); + model.leftArmPose = RenderUtils.getArmPose(raider, InteractionHand.OFF_HAND); + super.render(raider, p_115456_, p_115457_, p_115458_, p_115459_, p_115460_); + } } \ No newline at end of file diff --git a/src/main/java/com/minecolonies/core/client/render/mobs/egyptians/AbstractRendererEgyptian.java b/src/main/java/com/minecolonies/core/client/render/mobs/egyptians/AbstractRendererEgyptian.java index a7f67d48522..2887b1c82ae 100755 --- a/src/main/java/com/minecolonies/core/client/render/mobs/egyptians/AbstractRendererEgyptian.java +++ b/src/main/java/com/minecolonies/core/client/render/mobs/egyptians/AbstractRendererEgyptian.java @@ -1,12 +1,16 @@ package com.minecolonies.core.client.render.mobs.egyptians; import com.minecolonies.api.entity.mobs.egyptians.AbstractEntityEgyptian; +import com.minecolonies.core.client.render.RenderUtils; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelLayers; -import net.minecraft.client.renderer.entity.HumanoidMobRenderer; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.HumanoidMobRenderer; import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; -import net.minecraft.client.model.HumanoidModel; +import net.minecraft.world.InteractionHand; /** * Abstract for rendering Pirates. @@ -19,4 +23,12 @@ public AbstractRendererEgyptian(final EntityRendererProvider.Context context, fi this.addLayer(new ItemInHandLayer<>(this, context.getItemInHandRenderer())); this.addLayer(new HumanoidArmorLayer<>(this, new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)), context.getModelManager())); } + + @Override + public void render(T raider, float p_115456_, float p_115457_, PoseStack p_115458_, MultiBufferSource p_115459_, int p_115460_) + { + model.rightArmPose = RenderUtils.getArmPose(raider, InteractionHand.MAIN_HAND); + model.leftArmPose = RenderUtils.getArmPose(raider, InteractionHand.OFF_HAND); + super.render(raider, p_115456_, p_115457_, p_115458_, p_115459_, p_115460_); + } } \ No newline at end of file diff --git a/src/main/java/com/minecolonies/core/client/render/mobs/norsemen/AbstractRendererNorsemen.java b/src/main/java/com/minecolonies/core/client/render/mobs/norsemen/AbstractRendererNorsemen.java index 53cab73d3b5..4512f91b4e4 100755 --- a/src/main/java/com/minecolonies/core/client/render/mobs/norsemen/AbstractRendererNorsemen.java +++ b/src/main/java/com/minecolonies/core/client/render/mobs/norsemen/AbstractRendererNorsemen.java @@ -1,12 +1,16 @@ package com.minecolonies.core.client.render.mobs.norsemen; import com.minecolonies.api.entity.mobs.vikings.AbstractEntityNorsemen; +import com.minecolonies.core.client.render.RenderUtils; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelLayers; -import net.minecraft.client.renderer.entity.HumanoidMobRenderer; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.HumanoidMobRenderer; import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; -import net.minecraft.client.model.HumanoidModel; +import net.minecraft.world.InteractionHand; /** * Abstract for rendering amazons. @@ -19,4 +23,12 @@ public AbstractRendererNorsemen(final EntityRendererProvider.Context context, fi this.addLayer(new ItemInHandLayer<>(this, context.getItemInHandRenderer())); this.addLayer(new HumanoidArmorLayer<>(this, new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)), context.getModelManager())); } + + @Override + public void render(T raider, float p_115456_, float p_115457_, PoseStack p_115458_, MultiBufferSource p_115459_, int p_115460_) + { + model.rightArmPose = RenderUtils.getArmPose(raider, InteractionHand.MAIN_HAND); + model.leftArmPose = RenderUtils.getArmPose(raider, InteractionHand.OFF_HAND); + super.render(raider, p_115456_, p_115457_, p_115458_, p_115459_, p_115460_); + } } diff --git a/src/main/java/com/minecolonies/core/client/render/mobs/pirates/AbstractRendererPirate.java b/src/main/java/com/minecolonies/core/client/render/mobs/pirates/AbstractRendererPirate.java index 5ce3f5b99ab..50fba0dba8d 100755 --- a/src/main/java/com/minecolonies/core/client/render/mobs/pirates/AbstractRendererPirate.java +++ b/src/main/java/com/minecolonies/core/client/render/mobs/pirates/AbstractRendererPirate.java @@ -1,12 +1,16 @@ package com.minecolonies.core.client.render.mobs.pirates; import com.minecolonies.api.entity.mobs.pirates.AbstractEntityPirate; +import com.minecolonies.core.client.render.RenderUtils; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.model.HumanoidModel; import net.minecraft.client.model.geom.ModelLayers; -import net.minecraft.client.renderer.entity.HumanoidMobRenderer; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.client.renderer.entity.HumanoidMobRenderer; import net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer; import net.minecraft.client.renderer.entity.layers.ItemInHandLayer; -import net.minecraft.client.model.HumanoidModel; +import net.minecraft.world.InteractionHand; /** * Abstract for rendering Pirates. @@ -19,4 +23,12 @@ public AbstractRendererPirate(final EntityRendererProvider.Context context, fina this.addLayer(new ItemInHandLayer<>(this, context.getItemInHandRenderer())); this.addLayer(new HumanoidArmorLayer<>(this, new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_INNER_ARMOR)), new HumanoidModel<>(context.bakeLayer(ModelLayers.PLAYER_OUTER_ARMOR)), context.getModelManager())); } + + @Override + public void render(T raider, float p_115456_, float p_115457_, PoseStack p_115458_, MultiBufferSource p_115459_, int p_115460_) + { + model.rightArmPose = RenderUtils.getArmPose(raider, InteractionHand.MAIN_HAND); + model.leftArmPose = RenderUtils.getArmPose(raider, InteractionHand.OFF_HAND); + super.render(raider, p_115456_, p_115457_, p_115458_, p_115459_, p_115460_); + } } \ No newline at end of file diff --git a/src/main/java/com/minecolonies/core/entity/ai/combat/AttackMoveAI.java b/src/main/java/com/minecolonies/core/entity/ai/combat/AttackMoveAI.java index a1f8dfb2e15..756d377fd8b 100644 --- a/src/main/java/com/minecolonies/core/entity/ai/combat/AttackMoveAI.java +++ b/src/main/java/com/minecolonies/core/entity/ai/combat/AttackMoveAI.java @@ -14,7 +14,6 @@ import net.minecraft.world.entity.Mob; import static com.minecolonies.api.util.constant.Constants.HALF_ROTATION; -import static com.minecolonies.api.util.constant.GuardConstants.TURN_AROUND; /** * Moves the entity and triggers the attack @@ -144,7 +143,7 @@ protected IState tryAttack() if (user.getSensing().hasLineOfSight(target)) { pathAttempts = 0; - user.lookAt(target, (float) TURN_AROUND, (float) TURN_AROUND); + user.getLookControl().setLookAt(target); doAttack(target); nextAttackTime = user.level.getGameTime() + getAttackDelay(); } 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 3e2818df12a..d3da694774b 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 @@ -269,6 +269,7 @@ private double getAttackDamage() addDmg += user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(MELEE_DAMAGE); + // TODO: Recheck balancing, do we need this if (user.getHealth() <= user.getMaxHealth() * 0.2D) { addDmg *= 2; @@ -292,6 +293,7 @@ protected double getAttackDistance() @Override protected int getAttackDelay() { + // TODO: Not sure if we should make knights attack faster, they are intended to not scale in dmg, but health final int reload = KNIGHT_ATTACK_DELAY_BASE - user.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Adaptability) / 3; return Math.max(reload, KNIGHT_ATTACK_DELAY_MIN); } 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 439e9306352..22e95a04c30 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 @@ -71,7 +71,7 @@ public class RangerCombatAI extends AttackMoveAI /** * How many ticks we activate the bow before shooting */ - private static final int BOW_HOLDING_DELAY = 10; + private static final int BOW_HOLDING_DELAY = 40; /** * Bonus range for shooting while guarding @@ -111,7 +111,7 @@ public boolean canAttack() if (weaponSlot != -1) { user.getCitizenItemHandler().setHeldItem(InteractionHand.MAIN_HAND, weaponSlot); - if (nextAttackTime - BOW_HOLDING_DELAY >= user.level.getGameTime()) + if (nextAttackTime - BOW_HOLDING_DELAY >= user.level.getGameTime() && !user.isUsingItem()) { user.startUsingItem(InteractionHand.MAIN_HAND); } @@ -121,6 +121,19 @@ public boolean canAttack() return false; } + @Override + protected boolean checkForTarget() + { + final boolean validTarget = super.checkForTarget(); + + if (!validTarget && user.isUsingItem()) + { + user.stopUsingItem(); + } + + return validTarget; + } + @Override protected void doAttack(final LivingEntity target) { @@ -139,6 +152,7 @@ protected void doAttack(final LivingEntity target) user.getCitizenData().setVisibleStatus(ARCHER_COMBAT); user.swing(InteractionHand.MAIN_HAND); + user.stopUsingItem(); int amountOfArrows = 1; if (user.getCitizenColonyHandler().getColony().getResearchManager().getResearchEffects().getEffectStrength(DOUBLE_ARROWS) > 0) @@ -220,6 +234,7 @@ protected double getAttackDistance() @Override protected int getAttackDelay() { + // TODO: Maybe better for balancing to not increase damage and speed, looks odd and drains arrows/bow durability final int attackDelay = RANGED_ATTACK_DELAY_BASE - (user.getCitizenData().getCitizenSkillHandler().getLevel(Skill.Adaptability)); return Math.max(attackDelay, PHYSICAL_ATTACK_DELAY_MIN * 2); } diff --git a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderMeleeAI.java b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderMeleeAI.java index c2d3950d7d2..14561f495ea 100644 --- a/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderMeleeAI.java +++ b/src/main/java/com/minecolonies/core/entity/mobs/aitasks/RaiderMeleeAI.java @@ -6,7 +6,6 @@ import com.minecolonies.api.entity.mobs.AbstractEntityRaiderMob; import com.minecolonies.api.util.SoundUtils; import com.minecolonies.api.util.constant.Constants; -import com.minecolonies.core.MineColonies; import com.minecolonies.core.entity.ai.combat.AttackMoveAI; import com.minecolonies.core.entity.citizen.EntityCitizen; import com.minecolonies.core.entity.pathfinding.pathresults.PathResult; @@ -36,7 +35,7 @@ public class RaiderMeleeAI= user.level.getGameTime() && !user.isUsingItem() && !user.getMainHandItem().isEmpty()) + { + user.startUsingItem(InteractionHand.MAIN_HAND); + } + + return true; + } + + @Override + protected boolean checkForTarget() + { + final boolean validTarget = super.checkForTarget(); + + if (!validTarget && user.isUsingItem()) + { + user.stopUsingItem(); + } + + return validTarget; } @Override