Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lx01.projects.wolfiemod;
- import java.util.UUID;
- import java.util.function.Predicate;
- import javax.annotation.Nullable;
- public class Wolfie extends TamableAnimal implements NeutralMob {
- private static final EntityDataAccessor<Integer> REMAINING_ANGER_TIME = SynchedEntityData.defineId(Wolfie.class, EntityDataSerializers.INT);
- public static final Predicate<LivingEntity> PREY_SELECTOR = (entity) -> {
- EntityType<?> type = entity.getType();
- return (type == EntityType.MAGMA_CUBE && (((MagmaCube)entity).getSize() <= 2)) || type == EntityType.RABBIT || (type == EntityType.WOLF && ((Wolf)entity).isTame());
- };
- private static final float WILD_HEALTH_MAX = 8.0F;
- private static final float TAMED_HEALTH_MAX = 20.0F;
- private static final UniformInt PERSISTENT_ANGER_TIME = TimeUtil.rangeOfSeconds(20, 39);
- @Nullable
- private UUID persistentAngerTarget;
- public Wolfie (EntityType<? extends Wolfie> type, Level level) {
- super(type, level);
- this.setTame(false);
- this.setPathfindingMalus(BlockPathTypes.POWDER_SNOW, -1.0F);
- this.setPathfindingMalus(BlockPathTypes.DANGER_POWDER_SNOW, -1.0F);
- }
- protected void registerGoals () {
- this.goalSelector.addGoal(1, new FloatGoal(this));
- this.goalSelector.addGoal(1, new PanicGoal(this, 1.5D));
- this.goalSelector.addGoal(2, new Wolfie.SitGoal(this));
- this.goalSelector.addGoal(3, new LeapAtTargetGoal(this, 0.4F));
- this.goalSelector.addGoal(4, new MeleeAttackGoal(this, 1.0D, true));
- this.goalSelector.addGoal(5, new FollowOwnerGoal(this, 1.0D, 10.0F, 2.0F, false));
- this.goalSelector.addGoal(6, new WaterAvoidingRandomStrollGoal(this, 1.0D));
- this.goalSelector.addGoal(7, new LookAtPlayerGoal(this, Player.class, 8.0F));
- this.goalSelector.addGoal(7, new RandomLookAroundGoal(this));
- this.targetSelector.addGoal(1, new OwnerHurtByTargetGoal(this));
- this.targetSelector.addGoal(2, new OwnerHurtTargetGoal(this));
- this.targetSelector.addGoal(3, (new HurtByTargetGoal(this, new Class[1]{Player.class})).alertOthers(new Class[0]));
- this.targetSelector.addGoal(4, new NearestAttackableTargetGoal(this, Player.class, 10, true, false, this::isAngryAt));
- this.targetSelector.addGoal(5, new NearestAttackableTargetGoal(this, MagmaCube.class, true, false));
- this.targetSelector.addGoal(6, new ResetUniversalAngerTargetGoal(this, true));
- }
- public boolean fireImmune () {
- ResourceLocation key = Registry.REGISTRY.get(Registry.DIMENSION_TYPE_REGISTRY).getKey(this.level.dimensionType());
- if (key == null) return false;
- if (key.getNamespace() != "minecraft") return false;
- if (key.getPath() != "nether") return false;
- return true;
- }
- public static AttributeSupplier.Builder createAttributes () {
- return Mob.createMobAttributes().add(Attributes.MOVEMENT_SPEED, 0.3D).add(Attributes.MAX_HEALTH, 8.0D).add(Attributes.ATTACK_DAMAGE, 2.0D);
- }
- protected void defineSynchedData () {
- super.defineSynchedData();
- this.entityData.set(REMAINING_ANGER_TIME, 0);
- }
- protected void playStepSound (BlockPos pos, BlockState state) {}
- public void addAdditionalSaveData (CompoundTag nbt) {
- super.addAdditionalSaveData(nbt);
- this.addPersistentAngerSaveData(nbt);
- }
- public void readAdditionalSaveData (CompoundTag nbt) {
- super.readAdditionalSaveData(nbt);
- this.readPersistentAngerData(this.level, nbt);
- }
- protected SoundEvent getAmbientSound () {
- if (this.isAngry()) {
- return WolfieSounds.WOLFIE_ANGRY;
- } else if (this.random.nextInt(3) == 0) {
- return this.isTame() && this.getHealth() < 10.0F ? WolfieSounds.WOLFIE_IDLE_TAME_HEALTH_LOW : WOLFIE_IDLE_TAME;
- } else {
- return WolfieSounds.WOLFIE_IDLE;
- }
- }
- protected SoundEvent getHurtSound (DamageSource damage) {
- return WolfieSounds.WOLFIE_HURT;
- }
- protected SoundEvent getDeathSound () {
- return WolfieSounds.WOLFIE_DIED;
- }
- protected float getSoundVolume () {
- return 0.4F;
- }
- public void aiStep () {
- super.aiStep();
- if (!this.level.clientSide && !this.isPathfinding() && this.onGround) {
- this.shaking = true;
- this.shake = 0.0F;
- this.shakePrev = 0.0F;
- this.level.broadcastEntityEvent(this, (byte)8);
- }
- if (!this.level.clientSide) {
- this.updatePersistentAnger(this.level, true);
- }
- }
- private void cancelShake () {
- this.shaking = false;
- this.shake = 0.0F;
- this.shakePrev = 0.0F;
- }
- public void die (DamageSource source) {
- this.shaking = false;
- this.shake = 0.0F;
- this.shakePrev = 0.0F;
- super.die (source);
- }
- protected float getStandingEyeHeight (Pose pose, EntityDimensions dim) {
- return dim.height * 0.25F;
- }
- public int getMaxHeadXRot () {
- return 0;
- }
- public boolean hurt (DamageSource source, float amt) {
- if (this.isInvulnerableTo(source)) {
- return false;
- } else {
- Entity attacker = source.getEntity();
- if (!this.level.clientSide) {
- this.setOrderedToSit(false);
- }
- if (attacker instanceof MagmaCube) {
- amt = Math.floor(amt / 3.0F);
- }
- return super.hurt(source, amt);
- }
- }
- public boolean doHurtTarget (Entity target) {
- boolean canHurt = target.hurt(DamageSource.mobAttack(this), (float)Math.floor(this.getAttributeValue(Attributes.ATTACK_DAMAGE)));
- if (canHurt) {
- this.doEnchantDamageEffects(this, target);
- }
- return canHurt;
- }
- public void setTame (boolean tame) {
- super.setTame(tame);
- if (tame) {
- this.mood = 100;
- this.affection = 10;
- this.getAttribute(Attributes.MAX_HEALTH).setValue(20.0D);
- this.setHealth(20.0F);
- } else {
- this.getAttribute(Attributes.MAX_HEALTH).setValue(8.0D);
- }
- this.getAttribute(Attributes.ATTACK_DAMAGE).a(4.0D);
- }
- public int getMaxSpawnClusterSize () {
- return 3;
- }
- public int getRemainingPersistentAngerTime () {
- return this.entityData.getValue(REMAINING_ANGER_TIME).intValue();
- }
- public void setRemainingPersistenAngerTime (int time) {
- this.entityData.setValue(REMAINING_ANGER_TIME, time);
- }
- public void startPersistentAngerTimer () {
- this.setRemainingPersistentAngerTime(persistentAngerTime.sample(this.random));
- }
- @Nullable
- public UUID getPersistentAngerTarget () {
- return this.persistentAngerTarget;
- }
- public void setPersistentAngerTarget (@Nullable UUID target) {
- this.mood -= 40;
- this.persistentAngerTarget = target;
- }
- public boolean canBreed (Animal other) {
- return false;
- }
- public boolean canBeLeashed (Player leasher) {
- return !this.isAngry() && super.canBeLeashed(player);
- }
- public Vec3 getLeashOffset () {
- return new Vec3(0.0D, (double)(1.5F * this.getStandingEyeHeight()), (double)(this.getBbWidth() * 0.4F));
- }
- public void tick () {
- super.tick();
- }
- public InteractionResult mobInteract (Player user, InteractionHand hand) {
- if (this.mood <= 0 && !(this.getOwnerUUID() == user.getUUID())) {
- this.setPersistentAngerTarget(user.getUUID());
- }
- ItemStack holding = user.getItemInHand(hand);
- if (holding.is(Items.MAGMA_CREAM)) {
- if (this.isTame()) {
- if (this.getOwnerUUID() == user.getUUID()) {
- holding.setSize(holding.getSize() - 1);
- this.wrongFeederCount = 0;
- this.mood += 10;
- this.affection += 5;
- this.level.addParticle(ParticleTypes.HEART, this.getX(), this.getY(), this.getZ(), 0.0D, 0.3D, 0.0D);
- this.level.playLocalSound(this.getX(), this.getY(), this.getZ(), WolfieSounds.WOLFIE_INTERACT_POSITIVE, SoundSource.PLAYERS, 0.5F, 0.5F);
- return InteractionResult.SUCCESS;
- } else {
- if (this.wrongFeederCount >= 5) this.mood -= 5;
- this.wrongFeederCount++;
- return InteractionResult.PASS;
- }
- } else {
- if (this.random.nextInt(10) == 0) {
- this.level.addParticle(ParticleTypes.HEART, this.getX(), this.getY(), this.getZ(), 0.0D, 0.3D, 0.0D);
- this.setTame(true);
- return InteractionResult.SUCCESS;
- } else {
- this.level.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY(), this.getZ(), 0.0D, 0.3D, 0.0D);
- return InteractionResult.FAILURE;
- }
- }
- } else if (holding == ItemStack.EMPTY) {
- if (user.isCrouching()) {
- if (this.getOwnerUUID() == user.getUUID()) {
- this.mood -= 25;
- this.affection -= 5;
- this.pickUp(user, hand);
- return InteractionResult.SUCCESS;
- }
- } else {
- if (this.getOwnerUUID() == user.getUUID()) {
- if (this.mood < 50) {
- this.mood -= 5;
- } else if (this.mood >= 150) {
- this.mood += 5;
- }
- if (this.mood < 25) {
- this.affection--;
- return InteractionResult.FAILURE;
- } else if (this.mood >= 175) {
- this.affection++;
- return InteractionResult.SUCCESS;
- }
- } else {
- if (this.mood < 150) {
- this.mood -= 5;
- }
- if (this.mood < 50) {
- this.mood -= 5;
- }
- return InteractionResult.FAILURE;
- }
- }
- }
- return InteractionResult.PASS;
- }
- public boolean wantsToAttack (LivingEntity attacker, LivingEntity owner) {
- if (!(target instanceof Creeper) && !(target instanceof Ghast)) {
- return false;
- } else if (attacker instanceof Wolf) {
- Wolf wolfTarget = (Wolf)target;
- return !wolfTarget.isTame() || wolfTarget.getOwner() != owner;
- } else if (target instanceof Player && owner instanceof Player && !((Player)owner).canAttack((Player)target)) {
- return false;
- } else if (target instanceof AbstractHorse && ((AbstractHorse)target).isTamed()) {
- return false;
- } else if (target instanceof TameableAnimal && ((TamableAnimal)target).isTame()) {
- return false;
- } else {
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement