Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mysticsbiomes.common.entity.animal;
- import com.mysticsbiomes.init.MysticEntities;
- 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.server.level.ServerLevel;
- import net.minecraft.world.InteractionHand;
- import net.minecraft.world.InteractionResult;
- import net.minecraft.world.entity.*;
- import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
- import net.minecraft.world.entity.ai.attributes.Attributes;
- import net.minecraft.world.entity.ai.control.LookControl;
- import net.minecraft.world.entity.ai.control.MoveControl;
- import net.minecraft.world.entity.animal.*;
- import net.minecraft.world.entity.player.Player;
- import net.minecraft.world.item.Items;
- import net.minecraft.world.level.Level;
- /**
- * Red Pandas spawn in the Bamboo Blossom Forest, scouting out bamboo, and stealing items.
- */
- public class RedPanda extends Fox {
- private static final EntityDataAccessor<Byte> DATA_FLAGS_ID = SynchedEntityData.defineId(RedPanda.class, EntityDataSerializers.BYTE);
- public final AnimationState sleepingAnimationState = new AnimationState();
- public final AnimationState standingPoseAnimationState = new AnimationState();
- public RedPanda(EntityType<? extends RedPanda> type, Level level) {
- super(type, level);
- this.lookControl = new LookControl(this);
- this.moveControl = new MoveControl(this);
- }
- protected void defineSynchedData() {
- super.defineSynchedData();
- this.entityData.define(DATA_FLAGS_ID, (byte)0);
- }
- public static AttributeSupplier.Builder createAttributes() {
- return Mob.createMobAttributes().add(Attributes.MOVEMENT_SPEED, 1.0F).add(Attributes.MAX_HEALTH, 10.0D).add(Attributes.FOLLOW_RANGE, 32.0D).add(Attributes.ATTACK_DAMAGE, 2.0D);
- }
- public RedPanda getBreedOffspring(ServerLevel level, AgeableMob mob) {
- return MysticEntities.RED_PANDA.get().create(level);
- }
- @Override
- public EntityDimensions getDimensions(Pose pose) {
- return pose == Pose.STANDING ? EntityDimensions.scalable(0.5F, 1.125F) : super.getDimensions(pose);
- }
- @Override
- protected float getStandingEyeHeight(Pose pose, EntityDimensions dimensions) {
- return pose == Pose.STANDING ? 1.0F : super.getStandingEyeHeight(pose, dimensions);
- }
- public void addAdditionalSaveData(CompoundTag tag) {
- super.addAdditionalSaveData(tag);
- tag.putBoolean("IsSleeping", this.isSleeping());
- tag.putBoolean("IsStanding", this.isStanding());
- }
- public void readAdditionalSaveData(CompoundTag tag) {
- super.readAdditionalSaveData(tag);
- this.setSleeping(tag.getBoolean("IsSleeping"));
- this.setStanding(tag.getBoolean("IsStanding"));
- }
- public void tick() {
- super.tick();
- if (this.level().isClientSide()) {
- this.setupAnimationStates();
- }
- }
- private void setupAnimationStates() {
- this.sleepingAnimationState.animateWhen(this.isSleeping(), this.tickCount);
- if (this.isStanding()) {
- this.setPose(this.walkAnimation.isMoving() ? Pose.STANDING : Pose.SITTING);
- }
- }
- private boolean getFlag(int value) {
- return (this.entityData.get(DATA_FLAGS_ID) & value) != 0;
- }
- private void setFlag(int value, boolean b) {
- if (b) {
- this.entityData.set(DATA_FLAGS_ID, (byte)(this.entityData.get(DATA_FLAGS_ID) | value));
- } else {
- this.entityData.set(DATA_FLAGS_ID, (byte)(this.entityData.get(DATA_FLAGS_ID) & ~value));
- }
- }
- public boolean isSleeping() {
- return this.getFlag(4);
- }
- public void setSleeping(boolean sleeping) {
- this.setPose(sleeping ? Pose.SLEEPING : Pose.SITTING);
- this.setFlag(4, sleeping);
- }
- public boolean isStanding() {
- return this.getFlag(8);
- }
- public void setStanding(boolean standing) {
- this.setPose(standing ? Pose.STANDING : Pose.SITTING);
- this.setFlag(8, standing);
- }
- @Override
- public InteractionResult mobInteract(Player player, InteractionHand hand) {
- this.setSleeping(player.getMainHandItem().is(Items.STICK));
- this.setStanding(player.getMainHandItem().is(Items.PINK_PETALS));
- return super.mobInteract(player, hand);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement