Search in sources :

Example 1 with BlockSlime

use of net.minecraft.block.BlockSlime in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class EntityCollisionInjector method alterEntityMovementPost.

public static void alterEntityMovementPost(Entity entity, IntermediateMovementVariableStorage storage) {
    double dx = storage.dxyz.x();
    double dy = storage.dxyz.y();
    double dz = storage.dxyz.z();
    double origDx = storage.origDxyz.x();
    double origDy = storage.origDxyz.y();
    double origDz = storage.origDxyz.z();
    double origPosX = storage.origPosXyz.x();
    double origPosY = storage.origPosXyz.y();
    double origPosZ = storage.origPosXyz.z();
    boolean alreadyOnGround = storage.alreadyOnGround;
    double motionYBefore = storage.motionYBefore;
    float oldFallDistance = storage.oldFallDistance;
    ShipData worldBelow = ValkyrienUtils.getLastShipTouchedByEntity(entity);
    entity.collidedHorizontally = (motionInterfering(dx, origDx)) || (motionInterfering(dz, origDz));
    entity.collidedVertically = isDifSignificant(dy, origDy);
    entity.onGround = entity.collidedVertically && origDy < 0 || alreadyOnGround || entity.onGround;
    entity.collided = entity.collidedHorizontally || entity.collidedVertically;
    Vector3d entityPosInShip = new Vector3d(entity.posX, entity.posY - 0.20000000298023224D, entity.posZ);
    worldBelow.getShipTransform().transformPosition(entityPosInShip, TransformType.GLOBAL_TO_SUBSPACE);
    int j4 = MathHelper.floor(entityPosInShip.x);
    int l4 = MathHelper.floor(entityPosInShip.y);
    int i5 = MathHelper.floor(entityPosInShip.z);
    BlockPos blockpos = new BlockPos(j4, l4, i5);
    IBlockState iblockstate = entity.world.getBlockState(blockpos);
    Block block = iblockstate.getBlock();
    // fixes slime blocks
    if (block instanceof BlockSlime && !entity.isInWeb) {
        entity.motionY = motionYBefore;
    }
    entity.fallDistance = oldFallDistance;
    if (entity instanceof EntityLivingBase) {
        if (!entity.world.isRemote && entity.fallDistance > 3.0F && entity.onGround) {
            // System.out.println("LAND DAMNIT!");
            float f = MathHelper.ceil(entity.fallDistance - 3.0F);
            if (!iblockstate.getBlock().isAir(iblockstate, entity.world, blockpos)) {
                double d0 = Math.min(0.2F + f / 15.0F, 2.5D);
                int i = (int) (150.0D * d0);
                if (!iblockstate.getBlock().addLandingEffects(iblockstate, (WorldServer) entity.world, blockpos, iblockstate, (EntityLivingBase) entity, i)) {
                    ((WorldServer) entity.world).spawnParticle(EnumParticleTypes.BLOCK_DUST, entity.posX, entity.posY, entity.posZ, i, 0.0D, 0.0D, 0.0D, 0.15000000596046448D, Block.getStateId(iblockstate));
                }
            }
        }
    }
    if (entity.onGround) {
        if (entity.fallDistance > 0.0F) {
            // Responsible for breaking crops when you jump on them
            iblockstate.getBlock().onFallenUpon(entity.world, blockpos, entity, entity.fallDistance);
        }
        entity.fallDistance = 0.0F;
    } else if (entity.motionY < 0.0D) {
        entity.fallDistance = (float) (entity.fallDistance - entity.motionY);
    }
    if (/* entity.canTriggerWalking() **/
    entity instanceof EntityPlayer && !entity.isRiding()) {
        if (dy != origDy) {
            // if (!(entity.motionY > 0 && dy > 0)) {
            block.onLanded(entity.world, entity);
        // }
        }
        if (block != null && entity.onGround) {
            block.onEntityWalk(entity.world, blockpos, entity);
        }
        if (entity.distanceWalkedOnStepModified > entity.nextStepDistance && iblockstate.getMaterial() != Material.AIR) {
            entity.nextStepDistance = (int) entity.distanceWalkedOnStepModified + 1;
            /*
                 * if (this.isInWater()) { float f = MathHelper.sqrt_double(this.motionX *
                 * this.motionX * 0.20000000298023224D + this.motionY * this.motionY +
                 * this.motionZ * this.motionZ * 0.20000000298023224D) * 0.35F;
                 *
                 * if (f > 1.0F) { f = 1.0F; }
                 *
                 * this.playSound(this.getSwimSound(), f, 1.0F + (this.rand.nextFloat() -
                 * this.rand.nextFloat()) * 0.4F); }
                 */
            // System.out.println("Play a sound!");
            // entity.playStepSound(blockpos, block);
            // TODO: In future, replace this with entity.playStepSound()
            SoundType soundtype = block.getSoundType(entity.world.getBlockState(blockpos), entity.world, blockpos, entity);
            if (entity.world.getBlockState(blockpos.up()).getBlock() == Blocks.SNOW_LAYER) {
                soundtype = Blocks.SNOW_LAYER.getSoundType();
                entity.playSound(soundtype.getStepSound(), soundtype.getVolume() * 0.15F, soundtype.getPitch());
            } else if (!block.getDefaultState().getMaterial().isLiquid()) {
                entity.playSound(soundtype.getStepSound(), soundtype.getVolume() * 0.15F, soundtype.getPitch());
            }
        }
    }
    if (dx != origDx) {
        entity.motionX = dx;
    }
    if (dy != origDy) {
        if (!(entity.motionY > 0 && dy > 0)) {
            entity.motionY = 0;
        }
    }
    if (dz != origDz) {
        entity.motionZ = dz;
    }
}
Also used : SoundType(net.minecraft.block.SoundType) IBlockState(net.minecraft.block.state.IBlockState) ShipData(org.valkyrienskies.mod.common.ships.ShipData) WorldServer(net.minecraft.world.WorldServer) BlockSlime(net.minecraft.block.BlockSlime) Vector3d(org.joml.Vector3d) EntityLivingBase(net.minecraft.entity.EntityLivingBase) Block(net.minecraft.block.Block) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Block (net.minecraft.block.Block)1 BlockSlime (net.minecraft.block.BlockSlime)1 SoundType (net.minecraft.block.SoundType)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 BlockPos (net.minecraft.util.math.BlockPos)1 WorldServer (net.minecraft.world.WorldServer)1 Vector3d (org.joml.Vector3d)1 ShipData (org.valkyrienskies.mod.common.ships.ShipData)1