Skip to content

Commit

Permalink
warrior issues will be fixed tomorrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Toregeldi480 committed Dec 11, 2024
1 parent 5c2e9a8 commit 89933ff
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class BetterVillagesMod implements ModInitializer {
public void onInitialize() {
FabricDefaultAttributeRegistry.register(
ModEntities.WARRIOR,
WarriorEntity.createMobAttributes()
WarriorEntity.createWarriorAttributes()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

public class ModModelLayers {
public static final EntityModelLayer WARRIOR =
new EntityModelLayer(new Identifier(BetterVillagesMod.MOD_ID, "warrior"), "main");
new EntityModelLayer(new Identifier(BetterVillagesMod.MOD_ID, "warrior"), "root");
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class WarriorModel extends EntityModel<WarriorEntity> {
private final ModelPart mirrored;
private final ModelPart right_leg;
private final ModelPart left_leg;

public WarriorModel(ModelPart root) {
this.head = root.getChild("head");
this.nose = this.head.getChild("nose");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.toregeldi.bettervillagesmod.BetterVillagesMod;
import com.toregeldi.bettervillagesmod.entity.custom.WarriorEntity;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRendererFactory;
import net.minecraft.client.render.entity.MobEntityRenderer;
import net.minecraft.util.Identifier;

public class WarriorRenderer extends MobEntityRenderer<WarriorEntity, WarriorModel> {
public class WarriorRenderer extends EntityRenderer<WarriorEntity> {
public WarriorRenderer(EntityRendererFactory.Context context) {
super(context, new WarriorModel(context.getPart(ModModelLayers.WARRIOR)), 0.5f);
super(context);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,78 @@
import net.minecraft.entity.ai.goal.LookAroundGoal;
import net.minecraft.entity.ai.goal.MoveThroughVillageGoal;
import net.minecraft.entity.ai.goal.RevengeGoal;
import net.minecraft.entity.mob.HuskEntity;
import net.minecraft.entity.mob.PatrolEntity;
import net.minecraft.entity.mob.ZombieEntity;
import net.minecraft.entity.mob.ZombieVillagerEntity;
import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.mob.*;
import net.minecraft.entity.passive.IronGolemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.world.World;

public class WarriorEntity extends PatrolEntity {
public WarriorEntity(EntityType<? extends PatrolEntity> entityType, World world) {
public class WarriorEntity extends IronGolemEntity {
public WarriorEntity(EntityType<? extends IronGolemEntity> entityType, World world) {
super(entityType, world);
}

@Override
public void writeCustomDataToNbt(NbtCompound nbt) {
super.writeCustomDataToNbt(nbt);
}

@Override
public void readCustomDataFromNbt(NbtCompound nbt) {
super.readCustomDataFromNbt(nbt);
}

@Override
protected void initGoals() {
this.goalSelector.add(2, new PatrolGoal<WarriorEntity>(this, 1.0f, 1.0f));
this.goalSelector.add(3, new MoveThroughVillageGoal(this, 1.0f, false, 100, this::canOpenDoor));
this.goalSelector.add(4, new LookAroundGoal(this));
this.targetSelector.add(1, new RevengeGoal(this));
this.targetSelector.add(2, new ActiveTargetGoal(this, ZombieEntity.class, true));
this.targetSelector.add(2, new ActiveTargetGoal(this, ZombieVillagerEntity.class, true));
this.targetSelector.add(2, new ActiveTargetGoal(this, HuskEntity.class, true));
this.targetSelector.add(2, new ActiveTargetGoal(this, PlayerEntity.class, true));
this.targetSelector.add(2, new ActiveTargetGoal(this, MobEntity.class, 5, false, false, entity -> entity instanceof Monster && !(entity instanceof CreeperEntity)));
}

public static DefaultAttributeContainer.Builder createWarriorAttributes() {
return MobEntity.createMobAttributes()
.add(EntityAttributes.GENERIC_MAX_HEALTH, 40)
.add(EntityAttributes.GENERIC_MOVEMENT_SPEED, 0.75f)
.add(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE, 0.2f)
.add(EntityAttributes.GENERIC_ATTACK_DAMAGE, 10.0f);
}

@Override
public void tickMovement() {
super.tickMovement();

if (!this.getWorld().isClient) {
this.tickAngerLogic((ServerWorld)this.getWorld(), true);
}
}

@Override
public boolean shouldSpawnSprintingParticles() {
return this.getVelocity().horizontalLengthSquared() > 2.5000003E-7F && this.random.nextInt(5) == 0;
}

@Override
protected void attackLivingEntity(LivingEntity target) {
super.attackLivingEntity(target);
}

@Override
public boolean damage(DamageSource source, float amount) {
boolean bl = super.damage(source, amount);
if (bl) {
this.playSound(SoundEvents.ENTITY_PILLAGER_HURT, 1.0F, 1.0F);
}

return bl;
}

private boolean canOpenDoor() {
Expand Down

0 comments on commit 89933ff

Please sign in to comment.