mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 19:46:42 +01:00
Walls are hard, a study says
This commit is contained in:
parent
12a56dfe79
commit
c4c9d288a9
1 changed files with 30 additions and 0 deletions
|
@ -9,12 +9,16 @@ import com.minelittlepony.unicopia.entity.player.MagicReserves.Bar;
|
||||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||||
import com.minelittlepony.unicopia.util.MutableVector;
|
import com.minelittlepony.unicopia.util.MutableVector;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
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.damage.DamageSource;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.sound.SoundCategory;
|
import net.minecraft.sound.SoundCategory;
|
||||||
import net.minecraft.sound.SoundEvent;
|
import net.minecraft.sound.SoundEvent;
|
||||||
|
import net.minecraft.sound.SoundEvents;
|
||||||
import net.minecraft.util.Tickable;
|
import net.minecraft.util.Tickable;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
import net.minecraft.util.math.MathHelper;
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
@ -80,6 +84,11 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
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) {
|
||||||
|
|
||||||
|
if (entity.abilities.flying && entity.horizontalCollision) {
|
||||||
|
handleWallCollission(entity, velocity);
|
||||||
|
}
|
||||||
|
|
||||||
entity.abilities.flying = false;
|
entity.abilities.flying = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,6 +169,27 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
return pony.getSpecies() == Race.CHANGELING ? USounds.CHANGELING_BUZZ : USounds.WING_FLAP;
|
return pony.getSpecies() == Race.CHANGELING ? USounds.CHANGELING_BUZZ : USounds.WING_FLAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void handleWallCollission(PlayerEntity player, MutableVector velocity) {
|
||||||
|
|
||||||
|
if (!player.world.isClient) {
|
||||||
|
BlockPos pos = new BlockPos(player.getCameraPosVec(1).add(player.getRotationVec(1).normalize().multiply(2)));
|
||||||
|
|
||||||
|
BlockState state = player.world.getBlockState(pos);
|
||||||
|
|
||||||
|
if (!player.world.isAir(pos) && Block.isFaceFullSquare(state.getCollisionShape(player.world, pos), player.getHorizontalFacing().getOpposite())) {
|
||||||
|
double motion = Math.sqrt(getHorizontalMotion(player));
|
||||||
|
|
||||||
|
float distance = (float)(motion * 20 - 3);
|
||||||
|
|
||||||
|
if (distance > 0) {
|
||||||
|
player.playSound(distance > 4 ? SoundEvents.ENTITY_PLAYER_BIG_FALL : SoundEvents.ENTITY_PLAYER_SMALL_FALL, 1, 1);
|
||||||
|
|
||||||
|
player.damage(DamageSource.FLY_INTO_WALL, distance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void moveFlying(PlayerEntity player, MutableVector velocity) {
|
protected void moveFlying(PlayerEntity player, MutableVector velocity) {
|
||||||
applyThrust(player, velocity);
|
applyThrust(player, velocity);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue