Search in sources :

Example 11 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Railcraft by Railcraft.

the class CommandDebug method executeSubCommand.

@Override
public void executeSubCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length != 0)
        CommandHelpers.throwWrongUsage(sender, this);
    RayTraceResult rayTraceResult = MiscTools.rayTracePlayerLook((EntityPlayer) sender);
    List<String> debug = Collections.emptyList();
    switch(rayTraceResult.typeOfHit) {
        case ENTITY:
            Entity entity = rayTraceResult.entityHit;
            if (entity instanceof EntityMinecart) {
                debug = CartTools.getDebugOutput((EntityMinecart) entity);
            } else {
                CommandHelpers.throwWrongUsage(sender, this);
            }
            break;
        case BLOCK:
            World world = CommandHelpers.getWorld(sender);
            TileEntity tile = WorldPlugin.getBlockTile(world, rayTraceResult.getBlockPos());
            if (tile instanceof RailcraftTileEntity) {
                debug = ((RailcraftTileEntity) tile).getDebugOutput();
            } else {
                CommandHelpers.throwWrongUsage(sender, this);
            }
            break;
    }
    for (String s : debug) {
        printLine(sender, s);
    }
}
Also used : RailcraftTileEntity(mods.railcraft.common.blocks.RailcraftTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) Entity(net.minecraft.entity.Entity) RailcraftTileEntity(mods.railcraft.common.blocks.RailcraftTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) RailcraftTileEntity(mods.railcraft.common.blocks.RailcraftTileEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) World(net.minecraft.world.World) EntityMinecart(net.minecraft.entity.item.EntityMinecart)

Example 12 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Witchworks by Um-Mitternacht.

the class ItemKelpSeed method onItemRightClick.

@Override
@SuppressWarnings("ConstantConditions")
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    final RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, false);
    ItemStack stack = playerIn.getHeldItem(hand);
    if (raytraceresult == null) {
        return ActionResult.newResult(EnumActionResult.PASS, stack);
    } else {
        if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
            final BlockPos blockpos = raytraceresult.getBlockPos();
            if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, stack)) {
                return ActionResult.newResult(EnumActionResult.FAIL, stack);
            }
            final BlockPos up = blockpos.up();
            final IBlockState iblockstate = worldIn.getBlockState(blockpos);
            if (iblockstate.getMaterial().isSolid()) {
                // special case for handling block placement with water lilies
                BlockPos I = up.add(-1, 0, -1);
                BlockPos F = up.add(1, 1, 1);
                for (BlockPos blockPos : BlockPos.getAllInBox(I, F)) {
                    Block block = worldIn.getBlockState(blockPos).getBlock();
                    if (block != ModBlocks.CROP_KELP && block != Blocks.WATER) {
                        return ActionResult.newResult(EnumActionResult.FAIL, stack);
                    }
                }
                final net.minecraftforge.common.util.BlockSnapshot blocksnapshot = net.minecraftforge.common.util.BlockSnapshot.getBlockSnapshot(worldIn, up);
                if (net.minecraftforge.event.ForgeEventFactory.onPlayerBlockPlace(playerIn, blocksnapshot, net.minecraft.util.EnumFacing.UP, hand).isCanceled()) {
                    blocksnapshot.restore(true, false);
                    return ActionResult.newResult(EnumActionResult.FAIL, stack);
                }
                worldIn.setBlockState(up, this.crop.getDefaultState(), 11);
                if (!playerIn.capabilities.isCreativeMode) {
                    stack.shrink(1);
                }
                worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
                return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
            }
        }
        return ActionResult.newResult(EnumActionResult.FAIL, stack);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) net.minecraft.util(net.minecraft.util) RayTraceResult(net.minecraft.util.math.RayTraceResult) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 13 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class CallRunnerClient method onGetPrecipitationHeightClient.

public static BlockPos onGetPrecipitationHeightClient(World world, BlockPos posToCheck) {
    BlockPos pos = world.getPrecipitationHeight(posToCheck);
    // Servers shouldn't bother running this code
    Vector traceStart = new Vector(pos.getX() + .5D, Minecraft.getMinecraft().thePlayer.posY + 50D, pos.getZ() + .5D);
    Vector traceEnd = new Vector(pos.getX() + .5D, pos.getY() + .5D, pos.getZ() + .5D);
    //		System.out.println(traceStart);
    //		System.out.println(traceEnd);
    RayTraceResult result = CallRunner.onRayTraceBlocks(world, traceStart.toVec3d(), traceEnd.toVec3d(), true, true, false);
    if (result != null && result.typeOfHit != Type.MISS && result.getBlockPos() != null) {
        PhysicsWrapperEntity wrapper = ValkyrienWarfareMod.physicsManager.getObjectManagingPos(world, result.getBlockPos());
        if (wrapper != null) {
            //				System.out.println("test");
            Vector blockPosVector = new Vector(result.getBlockPos().getX() + .5D, result.getBlockPos().getY() + .5D, result.getBlockPos().getZ() + .5D);
            wrapper.wrapping.coordTransform.fromLocalToGlobal(blockPosVector);
            BlockPos toReturn = new BlockPos(pos.getX(), blockPosVector.Y + .5D, pos.getZ());
            return toReturn;
        }
    }
    return pos;
}
Also used : PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) Vector(ValkyrienWarfareBase.API.Vector)

Example 14 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class CallRunner method rayTraceBlocksIgnoreShip.

public static RayTraceResult rayTraceBlocksIgnoreShip(World world, Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock, PhysicsWrapperEntity toIgnore) {
    RayTraceResult vanillaTrace = world.rayTraceBlocks(vec31, vec32, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
    WorldPhysObjectManager physManager = ValkyrienWarfareMod.physicsManager.getManagerForWorld(world);
    if (physManager == null) {
        return vanillaTrace;
    }
    Vec3d playerEyesPos = vec31;
    Vec3d playerReachVector = vec32.subtract(vec31);
    AxisAlignedBB playerRangeBB = new AxisAlignedBB(vec31.xCoord, vec31.yCoord, vec31.zCoord, vec32.xCoord, vec32.yCoord, vec32.zCoord);
    List<PhysicsWrapperEntity> nearbyShips = physManager.getNearbyPhysObjects(playerRangeBB);
    //Get rid of the Ship that we're not supposed to be RayTracing for
    nearbyShips.remove(toIgnore);
    boolean changed = false;
    double reachDistance = playerReachVector.lengthVector();
    double worldResultDistFromPlayer = 420000000D;
    if (vanillaTrace != null && vanillaTrace.hitVec != null) {
        worldResultDistFromPlayer = vanillaTrace.hitVec.distanceTo(vec31);
    }
    for (PhysicsWrapperEntity wrapper : nearbyShips) {
        playerEyesPos = vec31;
        playerReachVector = vec32.subtract(vec31);
        // TODO: Re-enable
        if (world.isRemote) {
        // ValkyrienWarfareMod.proxy.updateShipPartialTicks(wrapper);
        }
        // Transform the coordinate system for the player eye pos
        playerEyesPos = RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.RwToLTransform, playerEyesPos);
        playerReachVector = RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.RwToLRotation, playerReachVector);
        Vec3d playerEyesReachAdded = playerEyesPos.addVector(playerReachVector.xCoord * reachDistance, playerReachVector.yCoord * reachDistance, playerReachVector.zCoord * reachDistance);
        RayTraceResult resultInShip = world.rayTraceBlocks(playerEyesPos, playerEyesReachAdded, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock);
        if (resultInShip != null && resultInShip.hitVec != null && resultInShip.typeOfHit == Type.BLOCK) {
            double shipResultDistFromPlayer = resultInShip.hitVec.distanceTo(playerEyesPos);
            if (shipResultDistFromPlayer < worldResultDistFromPlayer) {
                worldResultDistFromPlayer = shipResultDistFromPlayer;
                resultInShip.hitVec = RotationMatrices.applyTransform(wrapper.wrapping.coordTransform.RlToWTransform, resultInShip.hitVec);
                vanillaTrace = resultInShip;
            }
        }
    }
    return vanillaTrace;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) WorldPhysObjectManager(ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager) PhysicsWrapperEntity(ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Example 15 with RayTraceResult

use of net.minecraft.util.math.RayTraceResult in project SecurityCraft by Geforce132.

the class ItemModifiedBucket method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
    boolean flag = this.containedBlock == Blocks.AIR;
    RayTraceResult rayTraceResult = this.rayTrace(worldIn, playerIn, flag);
    if (rayTraceResult == null) {
        return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
    } else {
        ActionResult<ItemStack> result = ForgeEventFactory.onBucketUse(playerIn, worldIn, itemStackIn, rayTraceResult);
        if (result.getType() != EnumActionResult.FAIL)
            return ActionResult.newResult(EnumActionResult.PASS, result.getResult());
        if (rayTraceResult.typeOfHit == Type.BLOCK) {
            BlockPos blockpos = rayTraceResult.getBlockPos();
            if (!worldIn.isBlockModifiable(playerIn, blockpos)) {
                return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
            }
            if (flag) {
                if (!playerIn.canPlayerEdit(blockpos.offset(rayTraceResult.sideHit), rayTraceResult.sideHit, itemStackIn)) {
                    return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
                }
                IBlockState iblockstate = worldIn.getBlockState(blockpos);
                Material material = iblockstate.getBlock().getMaterial(iblockstate);
                //StatList.OBJECT_USE_STATS no longer accessible TODO check for 1.10.2 and 1.11.2
                if (material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) {
                    worldIn.setBlockToAir(blockpos);
                    //TODO StatList.OBJECT_USE_STATS
                    return ActionResult.newResult(EnumActionResult.PASS, fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fWaterBucket));
                }
                if (material == Material.LAVA && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) {
                    worldIn.setBlockToAir(blockpos);
                    //TODO StatList.OBJECT_USE_STATS
                    return ActionResult.newResult(EnumActionResult.PASS, fillBucket(itemStackIn, playerIn, mod_SecurityCraft.fLavaBucket));
                }
            } else {
                if (this.containedBlock == Blocks.AIR) {
                    return ActionResult.newResult(EnumActionResult.PASS, new ItemStack(Items.BUCKET));
                }
                BlockPos blockpos1 = blockpos.offset(rayTraceResult.sideHit);
                if (!playerIn.canPlayerEdit(blockpos1, rayTraceResult.sideHit, itemStackIn)) {
                    return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
                }
                if (this.tryPlaceContainedLiquid(worldIn, blockpos1) && !playerIn.capabilities.isCreativeMode) {
                    //TODO StatList.OBJECT_USE_STATS
                    return ActionResult.newResult(EnumActionResult.PASS, new ItemStack(Items.BUCKET));
                }
            }
        }
        return ActionResult.newResult(EnumActionResult.PASS, itemStackIn);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) Material(net.minecraft.block.material.Material) ItemStack(net.minecraft.item.ItemStack)

Aggregations

RayTraceResult (net.minecraft.util.math.RayTraceResult)32 ItemStack (net.minecraft.item.ItemStack)16 IBlockState (net.minecraft.block.state.IBlockState)12 Vec3d (net.minecraft.util.math.Vec3d)12 Entity (net.minecraft.entity.Entity)11 BlockPos (net.minecraft.util.math.BlockPos)11 TileEntity (net.minecraft.tileentity.TileEntity)9 Block (net.minecraft.block.Block)7 EntityPlayer (net.minecraft.entity.player.EntityPlayer)7 World (net.minecraft.world.World)7 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)6 EntityLivingBase (net.minecraft.entity.EntityLivingBase)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)4 ArrayList (java.util.ArrayList)4 Vector (ValkyrienWarfareBase.API.Vector)2 WorldPhysObjectManager (ValkyrienWarfareBase.PhysicsManagement.WorldPhysObjectManager)2 ChemthrowerEffect_Potion (blusunrize.immersiveengineering.api.tool.ChemthrowerHandler.ChemthrowerEffect_Potion)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 EntityArmorStand (net.minecraft.entity.item.EntityArmorStand)2