Jump to content

Recommended Posts

Posted

Entity Code:

package io.github.withonetee.entities;

import io.github.withonetee.init.ModEntity;
import net.minecraft.block.BlockState;
import net.minecraft.enchantment.Enchantments;
import net.minecraft.entity.*;
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
import net.minecraft.entity.ai.attributes.Attributes;
import net.minecraft.entity.ai.goal.*;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.IDyeableArmorItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.DamageSource;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.world.BossInfo;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerBossInfo;

public class FightingEntity extends MonsterEntity {

    private final ServerBossInfo bossInfo = (ServerBossInfo) (new ServerBossInfo(this.getDisplayName(), BossInfo.Color.RED, BossInfo.Overlay.PROGRESS)).setDarkenSky(true);
    public final ItemStack leather_helmet = new ItemStack(Items.LEATHER_HELMET);
    public final ItemStack cookie = new ItemStack(Items.COOKIE);

    public FightingEntity (EntityType<? extends MonsterEntity> type, World worldIn) {
        super(type, worldIn);
    }

    @Override
    public void onAddedToWorld() {
        super.onAddedToWorld();
        this.setSprinting(true);
        ((IDyeableArmorItem) leather_helmet.getItem()).setColor(leather_helmet, 0xBFA290);
        cookie.addEnchantment(Enchantments.KNOCKBACK, 2);
        this.setItemStackToSlot(EquipmentSlotType.MAINHAND, cookie);
        this.setItemStackToSlot(EquipmentSlotType.HEAD, leather_helmet);
    }

    public static AttributeModifierMap.MutableAttribute setCustomAttributes() {
        return MobEntity.func_233666_p_()
                .createMutableAttribute(Attributes.MAX_HEALTH, 300.0F)
                .createMutableAttribute(Attributes.MOVEMENT_SPEED, 0.4F)
                .createMutableAttribute(Attributes.ATTACK_KNOCKBACK, 3.0F)
                .createMutableAttribute(Attributes.ATTACK_SPEED, 100.0F)
                .createMutableAttribute(Attributes.ATTACK_DAMAGE, 5.0F)
                .createMutableAttribute(Attributes.ARMOR, 0.0F)
                .createMutableAttribute(Attributes.ARMOR_TOUGHNESS, 0.0F);
    }

    @Override
    public void registerGoals() {
        super.registerGoals();
    }

    @Override
    public int getExperiencePoints(PlayerEntity player) {
        return 25 +  this.world.rand.nextInt(50);
    }

    @Override
    public SoundEvent getAmbientSound() {
        return SoundEvents.ENTITY_CAT_AMBIENT;
    }

    @Override
    public SoundEvent getDeathSound() {
        return SoundEvents.ENTITY_CAT_DEATH;
    }

    public SoundEvent getHurtSound(DamageSource damageSourceIn) {
        return SoundEvents.ENTITY_CAT_HURT;
    }

    @Override
    public void playStepSound(BlockPos pos, BlockState blockIn) {
        this.playSound(SoundEvents.ENTITY_PIG_STEP, 1.0F, 1.0F);
    }

    @Override
    public boolean canSwim() {
        return true;
    }

    @Override
    public SoundEvent getSwimSound() {
        return SoundEvents.ENTITY_PLAYER_SWIM;
    }

    @Override
    public SoundEvent getSplashSound() {
        return SoundEvents.ENTITY_PLAYER_SPLASH;
    }

    @Override
    public SoundEvent getFallSound(int heightIn) {
        return SoundEvents.ENTITY_PLAYER_BIG_FALL;
    }

    @Override
    public boolean canBreatheUnderwater() {
        return true;
    }

    @Override
    public boolean preventDespawn() {
        return true;
    }

    @Override
    public boolean canDespawn(double distanceToClosestPlayer) {
        return false;
    }

    @Override
    public boolean isDespawnPeaceful() {
        return false;
    }

    @Override
    public boolean onLivingFall(float distance, float damageMultiplier) {
        return super.onLivingFall(distance, 0);
    }

    @Override
    public boolean isNonBoss() {
        return false;
    }

    @Override
    public void updateAITasks() {
        super.updateAITasks();
        bossInfo.setPercent(getHealth() / getMaxHealth());
    }

    @Override
    public void addTrackingPlayer(ServerPlayerEntity player) {
        super.addTrackingPlayer(player);
        bossInfo.addPlayer(player);
    }

    @Override
    public void removeTrackingPlayer(ServerPlayerEntity player) {
        super.removeTrackingPlayer(player);
        bossInfo.removePlayer(player);
    }
}

Renderer:

package io.github.withonetee.client.render;

import io.github.withonetee.Main;
import io.github.withonetee.client.model.EntityPlayerModel;
import io.github.withonetee.entities.FightingEntity;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.LivingRenderer;
import net.minecraft.client.renderer.entity.layers.BipedArmorLayer;
import net.minecraft.client.renderer.entity.layers.HeldItemLayer;
import net.minecraft.util.ResourceLocation;

public class EntityFightingRenderer extends LivingRenderer<FightingEntity, EntityPlayerModel<FightingEntity>> {

    public EntityFightingRenderer(EntityRendererManager manager) {
        super(manager, new EntityPlayerModel(0.0F, false), 0.5F);
        this.addLayer(new BipedArmorLayer<>(this, new EntityPlayerModel<>(0.5F, false), new EntityPlayerModel<>(1.0F, false)));
        this.addLayer(new HeldItemLayer<>(this));
    }

    @Override
    public ResourceLocation getEntityTexture(FightingEntity entity) {
        return new ResourceLocation(Main.MOD_ID, "textures/entity/entity.png");
    }
}

2020-12-21_12.28.47.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.