Bats don't mind bonking their heads. In fact they love it!

This commit is contained in:
Sollace 2020-10-02 14:58:45 +02:00
parent 4f9787a7b0
commit b59982761d
3 changed files with 40 additions and 10 deletions

View file

@ -39,7 +39,7 @@ public class BatPonyHangAbility implements Ability<Multi> {
return new Multi(BlockPos.ZERO, 0); return new Multi(BlockPos.ZERO, 0);
} }
BlockPos poss = RayTraceHelper.doTrace(player.getOwner(), 5, 1, EntityPredicates.EXCEPT_SPECTATOR).getBlockPos().orElse(null); BlockPos poss = RayTraceHelper.doTrace(player.getOwner(), 3, 1, EntityPredicates.EXCEPT_SPECTATOR).getBlockPos().orElse(null);
if (poss != null) { if (poss != null) {
boolean air = player.getWorld().isAir(poss.down()) && player.getWorld().isAir(poss.down(2)); boolean air = player.getWorld().isAir(poss.down()) && player.getWorld().isAir(poss.down(2));
@ -72,7 +72,10 @@ public class BatPonyHangAbility implements Ability<Multi> {
if (data.hitType == 1 && player.canHangAt(data.pos())) { if (data.hitType == 1 && player.canHangAt(data.pos())) {
player.getOwner().teleport(data.x + 0.5, data.y - 2, data.z + 0.5); player.getOwner().teleport(data.x + 0.5, data.y - 2, data.z + 0.5);
player.getOwner().setVelocity(Vec3d.ZERO); player.getOwner().setVelocity(Vec3d.ZERO);
attr.addPersistentModifier(PlayerAttributes.BAT_HANGING);
if (!attr.hasModifier(PlayerAttributes.BAT_HANGING)) {
attr.addPersistentModifier(PlayerAttributes.BAT_HANGING);
}
} }
} }

View file

@ -13,6 +13,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPose; import net.minecraft.entity.EntityPose;
import net.minecraft.entity.attribute.EntityAttributeInstance;
import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -83,7 +84,10 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
if (!creative) { if (!creative) {
entity.abilities.flying |= (canFly || entity.abilities.allowFlying) && isFlyingEither; entity.abilities.flying |= (canFly || entity.abilities.allowFlying) && isFlyingEither;
if ((entity.isOnGround() && entity.isSneaking()) || entity.isTouchingWater() || entity.horizontalCollision || entity.verticalCollision) { if ((entity.isOnGround() && entity.isSneaking())
|| entity.isTouchingWater()
|| entity.horizontalCollision
|| (entity.verticalCollision && (pony.getSpecies() != Race.BAT || velocity.y < 0))) {
if (entity.abilities.flying && entity.horizontalCollision) { if (entity.abilities.flying && entity.horizontalCollision) {
handleWallCollission(entity, velocity); handleWallCollission(entity, velocity);
@ -108,6 +112,17 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
if (canFly) { if (canFly) {
if (isFlying()) { if (isFlying()) {
if (pony.getSpecies() == Race.BAT && entity.verticalCollision && pony.canHangAt(pony.getOrigin().up(2))) {
EntityAttributeInstance attr = entity.getAttributeInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER);
if (!attr.hasModifier(PlayerAttributes.BAT_HANGING)) {
attr.addPersistentModifier(PlayerAttributes.BAT_HANGING);
entity.setVelocity(Vec3d.ZERO);
return;
}
}
int level = pony.getLevel().get() + 1; int level = pony.getLevel().get() + 1;
if (ticksInAir++ > (level * 100)) { if (ticksInAir++ > (level * 100)) {

View file

@ -34,6 +34,7 @@ import com.mojang.authlib.GameProfile;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.attribute.DefaultAttributeContainer; import net.minecraft.entity.attribute.DefaultAttributeContainer;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.data.DataTracker; import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData; import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry; import net.minecraft.entity.data.TrackedDataHandlerRegistry;
@ -81,6 +82,8 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
private boolean prevSneaking; private boolean prevSneaking;
private boolean prevLanded; private boolean prevLanded;
private int ticksHanging;
@Nullable @Nullable
private Race clientPreferredRace; private Race clientPreferredRace;
@ -255,21 +258,25 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
private BlockPos getHangingPos() { private BlockPos getHangingPos() {
BlockPos pos = getOrigin(); BlockPos pos = getOrigin();
return new BlockPos(pos.getX(), getOwner().getEyeY() + 1, pos.getZ()); return new BlockPos(pos.getX(), pos.getY() + entity.getEyeHeight(entity.getPose()) + 2, pos.getZ());
} }
@Override @Override
public void tick() { public void tick() {
if (isHanging()) { if (isHanging()) {
gravity.isFlyingSurvival = false; if (ticksHanging++ > 40) {
gravity.isFlyingEither = false; if (Entity.squaredHorizontalLength(entity.getVelocity()) > 0.01
entity.abilities.flying = false; || entity.isSneaking()
|| !canHangAt(getHangingPos())) {
if (Entity.squaredHorizontalLength(entity.getVelocity()) > 0.01 || entity.isSneaking() || !canHangAt(getHangingPos())) {
entity.getAttributes().getCustomInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER).removeModifier(PlayerAttributes.BAT_HANGING); entity.getAttributes().getCustomInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER).removeModifier(PlayerAttributes.BAT_HANGING);
entity.calculateDimensions(); entity.calculateDimensions();
}
} }
} else {
ticksHanging = 0;
} }
gravity.tick(); gravity.tick();
@ -303,6 +310,11 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
prevSneaking = entity.isSneaking(); prevSneaking = entity.isSneaking();
prevLanded = entity.isOnGround(); prevLanded = entity.isOnGround();
if (gravity.isGravityNegative() && entity.getY() > entity.world.getHeight() + 64) {
entity.damage(DamageSource.OUT_OF_WORLD, 4.0F);
}
} }
public Optional<Float> onImpact(float distance, float damageMultiplier) { public Optional<Float> onImpact(float distance, float damageMultiplier) {