Search in sources :

Example 11 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project SolarCraftRepository by FINDERFEED.

the class MeteoriteAbility method cast.

@Override
public void cast(ServerPlayer entity, ServerLevel world) {
    super.cast(entity, world);
    if (allowed) {
        Vec3 vec = entity.getLookAngle().multiply(200, 200, 200);
        ClipContext ctx = new ClipContext(entity.position().add(0, 1.5, 0), entity.position().add(0, 1.5, 0).add(vec), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity);
        BlockHitResult result = world.clip(ctx);
        if (result.getType() == HitResult.Type.BLOCK) {
            BlockPos pos = result.getBlockPos();
            if (world.canSeeSky(pos.above())) {
                MeteoriteProjectile proj = new MeteoriteProjectile(entity, world);
                Vector3f posVect = new Vector3f((float) entity.position().x - (float) entity.getLookAngle().x * 20, (float) entity.position().y + 64, (float) entity.position().z - (float) entity.getLookAngle().z * 20);
                proj.setPos(posVect.x(), posVect.y(), posVect.z());
                Vec3 velocity = new Vec3(pos.offset(0.5, 0, 0.5).getX() - posVect.x(), pos.offset(0.5, 0, 0.5).getY() - posVect.y(), pos.offset(0.5, 0, 0.5).getZ() - posVect.z());
                proj.setDeltaMovement(velocity.normalize());
                world.addFreshEntity(proj);
            } else {
                if (!entity.isCreative()) {
                    refund(entity);
                }
            }
        }
    }
}
Also used : MeteoriteProjectile(com.finderfeed.solarforge.SolarAbilities.meteorite.MeteoriteProjectile) ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) Vector3f(com.mojang.math.Vector3f) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 12 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project SolarCraftRepository by FINDERFEED.

the class SolarStrikeAbility method cast.

@Override
public void cast(ServerPlayer entity, ServerLevel world) {
    super.cast(entity, world);
    if (allowed) {
        Vec3 vec = entity.getLookAngle().multiply(200, 200, 200);
        ClipContext ctx = new ClipContext(entity.position().add(0, 1.5, 0), entity.position().add(0, 1.5, 0).add(vec), ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, entity);
        BlockHitResult result = world.clip(ctx);
        if (result.getType() == HitResult.Type.BLOCK) {
            BlockPos pos = result.getBlockPos();
            if (world.canSeeSky(pos.above())) {
                SolarStrikeEntity entityBolt = new SolarStrikeEntity(SolarForge.SOLAR_STRIKE_ENTITY_REG.get(), world);
                entityBolt.setPos(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
                world.addFreshEntity(entityBolt);
            } else {
                if (!entity.isCreative()) {
                    refund(entity);
                }
            }
        }
    }
}
Also used : ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) SolarStrikeEntity(com.finderfeed.solarforge.SolarAbilities.SolarStrikeEntity)

Example 13 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project SolarCraftRepository by FINDERFEED.

the class MyFallingBlockEntity method tick.

public void tick() {
    if (this.blockState.isAir()) {
        this.discard();
    } else {
        Block block = this.blockState.getBlock();
        ++this.time;
        if (!this.isNoGravity()) {
            this.setDeltaMovement(this.getDeltaMovement().add(0.0D, -0.04D, 0.0D));
        }
        this.move(MoverType.SELF, this.getDeltaMovement());
        if (!this.level.isClientSide) {
            BlockPos blockpos = this.blockPosition();
            boolean flag = this.blockState.getBlock() instanceof ConcretePowderBlock;
            boolean flag1 = flag && this.level.getFluidState(blockpos).is(FluidTags.WATER);
            double d0 = this.getDeltaMovement().lengthSqr();
            if (flag && d0 > 1.0D) {
                BlockHitResult blockhitresult = this.level.clip(new ClipContext(new Vec3(this.xo, this.yo, this.zo), this.position(), ClipContext.Block.COLLIDER, ClipContext.Fluid.SOURCE_ONLY, this));
                if (blockhitresult.getType() != HitResult.Type.MISS && this.level.getFluidState(blockhitresult.getBlockPos()).is(FluidTags.WATER)) {
                    blockpos = blockhitresult.getBlockPos();
                    flag1 = true;
                }
            }
            if (!this.onGround && !flag1) {
                if (!this.level.isClientSide && (this.time > 100 && (blockpos.getY() <= this.level.getMinBuildHeight() || blockpos.getY() > this.level.getMaxBuildHeight()) || this.time > 600)) {
                    if (this.dropItem && this.level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
                        this.spawnAtLocation(block);
                    }
                    this.discard();
                }
            } else {
                BlockState blockstate = this.level.getBlockState(blockpos);
                this.setDeltaMovement(this.getDeltaMovement().multiply(0.7D, -0.5D, 0.7D));
                if (!blockstate.is(Blocks.MOVING_PISTON)) {
                    if (!this.cancelDrop) {
                        boolean flag2 = blockstate.canBeReplaced(new DirectionalPlaceContext(this.level, blockpos, Direction.DOWN, ItemStack.EMPTY, Direction.UP));
                        boolean flag3 = FallingBlock.isFree(this.level.getBlockState(blockpos.below())) && (!flag || !flag1);
                        boolean flag4 = this.blockState.canSurvive(this.level, blockpos) && !flag3;
                        if (flag2 && flag4) {
                            if (this.blockState.hasProperty(BlockStateProperties.WATERLOGGED) && this.level.getFluidState(blockpos).getType() == Fluids.WATER) {
                                this.blockState = this.blockState.setValue(BlockStateProperties.WATERLOGGED, true);
                            }
                            if (this.level.setBlock(blockpos, this.blockState, 3)) {
                                ((ServerLevel) this.level).getChunkSource().chunkMap.broadcast(this, new ClientboundBlockUpdatePacket(blockpos, this.level.getBlockState(blockpos)));
                                this.discard();
                                if (this.blockData != null && this.blockState.hasBlockEntity()) {
                                    BlockEntity blockentity = this.level.getBlockEntity(blockpos);
                                    if (blockentity != null) {
                                        CompoundTag compoundtag = blockentity.saveWithoutMetadata();
                                        for (String s : this.blockData.getAllKeys()) {
                                            compoundtag.put(s, this.blockData.get(s).copy());
                                        }
                                        try {
                                            blockentity.load(compoundtag);
                                        } catch (Exception exception) {
                                            SolarForge.LOGGER.error("Failed to load block entity from falling block", (Throwable) exception);
                                        }
                                        blockentity.setChanged();
                                    }
                                }
                            } else if (this.dropItem && this.level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
                                this.discard();
                                this.callOnBrokenAfterFall(block, blockpos);
                                this.spawnAtLocation(block);
                            }
                        } else {
                            this.discard();
                            if (this.dropItem && this.level.getGameRules().getBoolean(GameRules.RULE_DOENTITYDROPS)) {
                                this.callOnBrokenAfterFall(block, blockpos);
                                this.spawnAtLocation(block);
                            }
                        }
                    } else {
                        this.discard();
                        this.callOnBrokenAfterFall(block, blockpos);
                    }
                }
            }
        }
        this.setDeltaMovement(this.getDeltaMovement().scale(0.98D));
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ClipContext(net.minecraft.world.level.ClipContext) ClientboundBlockUpdatePacket(net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket) BlockState(net.minecraft.world.level.block.state.BlockState) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) BlockHitResult(net.minecraft.world.phys.BlockHitResult) DirectionalPlaceContext(net.minecraft.world.item.context.DirectionalPlaceContext) CompoundTag(net.minecraft.nbt.CompoundTag) FallingBlockEntity(net.minecraft.world.entity.item.FallingBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 14 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project SolarCraftRepository by FINDERFEED.

the class FinderfeedMathHelper method canSeeTileEntity.

public static boolean canSeeTileEntity(BlockEntity tile, BlockEntity start, double radius) {
    Vec3 startPos = new Vec3(start.getBlockPos().getX() + 0.5, start.getBlockPos().getY() + 0.5, start.getBlockPos().getZ() + 0.5);
    Vec3 tileEntityPos = new Vec3(tile.getBlockPos().getX() + 0.5, tile.getBlockPos().getY() + 0.5, tile.getBlockPos().getZ() + 0.5);
    Vec3 between = new Vec3(tileEntityPos.x - startPos.x, tileEntityPos.y - startPos.y, tileEntityPos.z - startPos.z);
    if (between.length() <= radius) {
        ClipContext ctx = new ClipContext(startPos.add(between.normalize().x, between.normalize().y, between.normalize().z), tileEntityPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null);
        BlockHitResult res = start.getLevel().clip(ctx);
        if (equalsBlockPos(tile.getBlockPos(), res.getBlockPos())) {
            return true;
        }
    }
    return false;
}
Also used : ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Example 15 with BlockHitResult

use of net.minecraft.world.phys.BlockHitResult in project SolarCraftRepository by FINDERFEED.

the class FinderfeedMathHelper method canSeeTileEntity.

public static boolean canSeeTileEntity(BlockEntity tile, Player player) {
    Vec3 playerHeadPos = player.position().add(0, player.getStandingEyeHeight(player.getPose(), player.getDimensions(player.getPose())), 0);
    Vec3 tileEntityPos = new Vec3(tile.getBlockPos().getX() + 0.5, tile.getBlockPos().getY() + 0.5, tile.getBlockPos().getZ() + 0.5);
    ClipContext ctx = new ClipContext(playerHeadPos, tileEntityPos, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, null);
    BlockHitResult res = player.level.clip(ctx);
    if (equalsBlockPos(tile.getBlockPos(), res.getBlockPos())) {
        return true;
    }
    return false;
}
Also used : ClipContext(net.minecraft.world.level.ClipContext) Vec3(net.minecraft.world.phys.Vec3) BlockHitResult(net.minecraft.world.phys.BlockHitResult)

Aggregations

BlockHitResult (net.minecraft.world.phys.BlockHitResult)181 BlockPos (net.minecraft.core.BlockPos)117 Vec3 (net.minecraft.world.phys.Vec3)79 BlockState (net.minecraft.world.level.block.state.BlockState)66 ItemStack (net.minecraft.world.item.ItemStack)63 HitResult (net.minecraft.world.phys.HitResult)51 Direction (net.minecraft.core.Direction)46 Level (net.minecraft.world.level.Level)41 ClipContext (net.minecraft.world.level.ClipContext)33 Player (net.minecraft.world.entity.player.Player)32 ServerLevel (net.minecraft.server.level.ServerLevel)23 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)20 Entity (net.minecraft.world.entity.Entity)19 InteractionHand (net.minecraft.world.InteractionHand)18 BlockPlaceContext (net.minecraft.world.item.context.BlockPlaceContext)18 ServerPlayer (net.minecraft.server.level.ServerPlayer)17 LivingEntity (net.minecraft.world.entity.LivingEntity)17 AABB (net.minecraft.world.phys.AABB)17 EntityHitResult (net.minecraft.world.phys.EntityHitResult)17 Minecraft (net.minecraft.client.Minecraft)16