Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by Maxmos ( 3 years ago )
package com.maxmos.zeldaacj.entity.custom;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.Pose;
import net.minecraftforge.entity.PartEntity;

public class GuardianStalkerPart extends PartEntity<GuardianStalkerEntity> {

    private static final EntityDataAccessor<Float> DATA_ID_MAX_HEALTH = SynchedEntityData.defineId(GuardianStalkerPart.class, EntityDataSerializers.FLOAT);
    private static final EntityDataAccessor<Float> DATA_ID_CURRENT_HEALTH = SynchedEntityData.defineId(GuardianStalkerPart.class, EntityDataSerializers.FLOAT);
    private static final EntityDataAccessor<Boolean> DATA_ID_IS_DEACTIVATED = SynchedEntityData.defineId(GuardianStalkerPart.class, EntityDataSerializers.BOOLEAN);

    public final GuardianStalkerEntity parentMob;
    public final String name;
    private EntityDimensions size;

    public GuardianStalkerPart(GuardianStalkerEntity entity, String name, float width, float height) {
        super(entity);
        this.size = EntityDimensions.scalable(width, height);
        this.refreshDimensions();
        this.parentMob = entity;
        this.name = name;
    }

    @Override
    public boolean hurt(DamageSource source, float amount) {
        //System.out.println(amount + " Part Amount");
        return this.isInvulnerableTo(source) ? false : this.parentMob.hurt(this, source, amount);
    }

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

    @Override
    protected void defineSynchedData() {
        this.entityData.define(DATA_ID_MAX_HEALTH, 90.0f);
        this.entityData.define(DATA_ID_CURRENT_HEALTH, this.getMaxHealth());
        this.entityData.define(DATA_ID_IS_DEACTIVATED, false);
    }

    public void killPart(){
        this.kill();
        this.refreshDimensions();
    }

    public void setMaxHealth(float health){
        this.entityData.set(DATA_ID_CURRENT_HEALTH, health);
    }

    public float getMaxHealth(){
        return this.entityData.get(DATA_ID_MAX_HEALTH);
    }
    public void setHealth(float health){
        this.entityData.set(DATA_ID_CURRENT_HEALTH, health);
    }

    public float getHealth(){
       return this.entityData.get(DATA_ID_CURRENT_HEALTH);
    }

    void setPartDeactivated(){
        this.entityData.set(DATA_ID_IS_DEACTIVATED, true);
        this.killPart();
    }

    public boolean isPartDeactivated(){
        return this.entityData.get(DATA_ID_IS_DEACTIVATED);
    }

    @Override
    public boolean isPickable() {
        return isPartDeactivated() ? false : true;
    }

    @Override
    public boolean isAttackable() {
        return isPartDeactivated() ? false : true;
    }

    @Override
    public boolean canBeCollidedWith() {
        return isPartDeactivated() ? false : true;
    }

    @Override
    public EntityDimensions getDimensions(Pose pose) {
        return size;
    }

    @Override
    protected void readAdditionalSaveData(CompoundTag tag) {
    }

    @Override
    protected void addAdditionalSaveData(CompoundTag tag) {

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

 

Revise this Paste

Your Name: Code Language: