Skip to content

Commit

Permalink
Raider improvements (#10413)
Browse files Browse the repository at this point in the history
Raiders and guards now properly look at their target while fighting
Raiders do now also properly display item use animations, spear/bow etc
Archer raiders now also draw their bow in preparation of shooting
Raiders no longer scale in attackspeed, as they already scale in damage with difficulty
  • Loading branch information
someaddons authored Nov 6, 2024
1 parent e7a4af7 commit 9b7eed5
Show file tree
Hide file tree
Showing 14 changed files with 263 additions and 84 deletions.
32 changes: 32 additions & 0 deletions src/main/java/com/minecolonies/api/util/LookHandler.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
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;

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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -61,12 +57,8 @@ public void render(

final CitizenModel<AbstractEntityCitizen> 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)
{
Expand Down Expand Up @@ -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<AbstractEntityCitizen> 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)
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/com/minecolonies/core/client/render/RenderUtils.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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_);
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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_);
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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_);
}
}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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_);
}
}
Loading

0 comments on commit 9b7eed5

Please sign in to comment.