mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-08 06:26:43 +01:00
Bats don't mind bonking their heads. In fact they love it!
This commit is contained in:
parent
4f9787a7b0
commit
b59982761d
3 changed files with 40 additions and 10 deletions
|
@ -39,7 +39,7 @@ public class BatPonyHangAbility implements Ability<Multi> {
|
|||
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) {
|
||||
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())) {
|
||||
player.getOwner().teleport(data.x + 0.5, data.y - 2, data.z + 0.5);
|
||||
player.getOwner().setVelocity(Vec3d.ZERO);
|
||||
attr.addPersistentModifier(PlayerAttributes.BAT_HANGING);
|
||||
|
||||
if (!attr.hasModifier(PlayerAttributes.BAT_HANGING)) {
|
||||
attr.addPersistentModifier(PlayerAttributes.BAT_HANGING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityPose;
|
||||
import net.minecraft.entity.attribute.EntityAttributeInstance;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
@ -83,7 +84,10 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
|||
if (!creative) {
|
||||
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) {
|
||||
handleWallCollission(entity, velocity);
|
||||
|
@ -108,6 +112,17 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
|||
|
||||
if (canFly) {
|
||||
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;
|
||||
|
||||
if (ticksInAir++ > (level * 100)) {
|
||||
|
|
|
@ -34,6 +34,7 @@ import com.mojang.authlib.GameProfile;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.attribute.DefaultAttributeContainer;
|
||||
import net.minecraft.entity.damage.DamageSource;
|
||||
import net.minecraft.entity.data.DataTracker;
|
||||
import net.minecraft.entity.data.TrackedData;
|
||||
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
|
||||
|
@ -81,6 +82,8 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
|||
private boolean prevSneaking;
|
||||
private boolean prevLanded;
|
||||
|
||||
private int ticksHanging;
|
||||
|
||||
@Nullable
|
||||
private Race clientPreferredRace;
|
||||
|
||||
|
@ -255,21 +258,25 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
|||
|
||||
private BlockPos getHangingPos() {
|
||||
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
|
||||
public void tick() {
|
||||
|
||||
if (isHanging()) {
|
||||
gravity.isFlyingSurvival = false;
|
||||
gravity.isFlyingEither = false;
|
||||
entity.abilities.flying = false;
|
||||
if (ticksHanging++ > 40) {
|
||||
if (Entity.squaredHorizontalLength(entity.getVelocity()) > 0.01
|
||||
|| 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.calculateDimensions();
|
||||
|
||||
entity.getAttributes().getCustomInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER).removeModifier(PlayerAttributes.BAT_HANGING);
|
||||
entity.calculateDimensions();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ticksHanging = 0;
|
||||
}
|
||||
|
||||
gravity.tick();
|
||||
|
@ -303,6 +310,11 @@ public class Pony implements Caster<PlayerEntity>, Equine<PlayerEntity>, Transmi
|
|||
|
||||
prevSneaking = entity.isSneaking();
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue