public static Vec3d toVec3(BlockVector3 vector) { return new Vec3d(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); }
@Override public Vec3d getSkyColor( final Entity cameraEntity, final float partialTicks ) { return new Vec3d( 0.07, 0.07, 0.07 ); }
@Override public Vec3d getFogColor( final float par1, final float par2 ) { return new Vec3d( 0.07, 0.07, 0.07 ); }
public Vec3d toVec3D() { return new Vec3d(x, y, z); }
public static RayTraceResult raytraceEntityPlayerLook(EntityPlayer player, float range) { Vec3d eye = new Vec3d(player.posX, player.posY + player.getEyeHeight(), player.posZ); // Entity.getPositionEyes Vec3d look = player.getLook(1.0f); return raytraceEntity(player, eye, look, range, true); }
private static EnumMap<EnumFacing, List<Vec3d>> generateCornersForFacings() { EnumMap<EnumFacing, List<Vec3d>> result = new EnumMap<>( EnumFacing.class ); for( EnumFacing facing : EnumFacing.values() ) { List<Vec3d> corners; float offset = ( facing.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ) ? 0 : 1; switch( facing.getAxis() ) { default: case X: corners = Lists.newArrayList( new Vec3d( offset, 1, 1 ), new Vec3d( offset, 0, 1 ), new Vec3d( offset, 0, 0 ), new Vec3d( offset, 1, 0 ) ); break; case Y: corners = Lists.newArrayList( new Vec3d( 1, offset, 1 ), new Vec3d( 1, offset, 0 ), new Vec3d( 0, offset, 0 ), new Vec3d( 0, offset, 1 ) ); break; case Z: corners = Lists.newArrayList( new Vec3d( 0, 1, offset ), new Vec3d( 0, 0, offset ), new Vec3d( 1, 0, offset ), new Vec3d( 1, 1, offset ) ); break; } if( facing.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ) { corners = Lists.reverse( corners ); } result.put( facing, ImmutableList.copyOf( corners ) ); } return result; }
@Override public boolean onActivated( final World w, final BlockPos pos, final EntityPlayer player, final EnumHand hand, final @Nullable ItemStack heldItem, final EnumFacing side, final float hitX, final float hitY, final float hitZ ) { return this.cb( w, pos ).activate( player, hand, new Vec3d( hitX, hitY, hitZ ) ); }
/** * Gets the view point of a player * * @param player player with head * * @return view point of player */ private Vec3d getCorrectedHeadVec( final EntityPlayer player ) { double x = player.posX; double y = player.posY; double z = player.posZ; if( player.world.isRemote ) { // compatibility with eye height changing mods y += player.getEyeHeight() - player.getDefaultEyeHeight(); } else { y += player.getEyeHeight(); if( player instanceof EntityPlayerMP && player.isSneaking() ) { y -= 0.08; } } return new Vec3d( x, y, z ); }
@Nonnull @Override public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float par8, float par9, float par10) { if(player.isSneaking()) { Block block = world.getBlockState(pos).getBlock(); if(block != null) { if(block instanceof ILexiconable) { ItemStack stack = player.getHeldItem(hand); LexiconEntry entry = ((ILexiconable) block).getEntry(world, pos, player, stack); if(entry != null && isKnowledgeUnlocked(stack, entry.getKnowledgeType())) { Botania.proxy.setEntryToOpen(entry); Botania.proxy.setLexiconStack(stack); openBook(player, stack, world, false); return EnumActionResult.SUCCESS; } } else if(world.isRemote) { RayTraceResult mop = new RayTraceResult(new Vec3d(par8, par9, par10), side, pos); return Botania.proxy.openWikiPage(world, block, mop) ? EnumActionResult.SUCCESS : EnumActionResult.FAIL; } } } return EnumActionResult.PASS; }
@Override public EnumActionResult onItemUseFirst( final EntityPlayer player, final World world, final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand ) { final RayTraceResult mop = new RayTraceResult( new Vec3d( hitX, hitY, hitZ ), side, pos ); final TileEntity te = world.getTileEntity( pos ); if( te instanceof IPartHost ) { final SelectedPart part = ( (IPartHost) te ).selectPart( mop.hitVec ); if( part.part != null || part.facade != null ) { if( part.part instanceof INetworkToolAgent && !( (INetworkToolAgent) part.part ).showNetworkInfo( mop ) ) { return EnumActionResult.FAIL; } else if( player.isSneaking() ) { return EnumActionResult.PASS; } } } else if( te instanceof INetworkToolAgent && !( (INetworkToolAgent) te ).showNetworkInfo( mop ) ) { return EnumActionResult.FAIL; } if( Platform.isClient() ) { NetworkHandler.instance().sendToServer( new PacketClick( pos, side, hitX, hitY, hitZ, hand ) ); } return EnumActionResult.SUCCESS; }
@Override @Optional.Method(modid="albedo") public Light provideLight() { int color = getColor(); return Light.builder().pos(new Vec3d(posX - motionX, posY - motionY, posZ - motionZ)).color(color, false).radius(getParticleSize() * 8).build(); }
public static RayTraceResult raytraceFromEntity(World worldIn, Entity playerIn, boolean useLiquids, double range) { float f = playerIn.rotationPitch; float f1 = playerIn.rotationYaw; double d0 = playerIn.posX; double d1 = playerIn.posY + (double)playerIn.getEyeHeight(); double d2 = playerIn.posZ; Vec3d vec3d = new Vec3d(d0, d1, d2); float f2 = MathHelper.cos(-f1 * 0.017453292F - (float)Math.PI); float f3 = MathHelper.sin(-f1 * 0.017453292F - (float)Math.PI); float f4 = -MathHelper.cos(-f * 0.017453292F); float f5 = MathHelper.sin(-f * 0.017453292F); float f6 = f3 * f4; float f7 = f2 * f4; double d3 = range; // Botania - use custom range param, don't limit to reach distance /*if (playerIn instanceof net.minecraft.entity.player.EntityPlayerMP) { d3 = ((net.minecraft.entity.player.EntityPlayerMP)playerIn).interactionManager.getBlockReachDistance(); }*/ Vec3d vec3d1 = vec3d.add((double)f6 * d3, (double)f5 * d3, (double)f7 * d3); return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false); }
ImmutableList<BlockPos> extraBlocks = ((IAoeTool) tool.getItem()).getAOEBlocks(tool, world, player, mop.getBlockPos()); for(BlockPos pos : extraBlocks) { event.getContext().drawSelectionBox(player, new RayTraceResult(new Vec3d(0, 0, 0), null, pos), 0, event.getPartialTicks());
protected RayTraceResult raytraceFromEntity(World worldIn, EntityPlayer playerIn, boolean useLiquids) { float f = playerIn.rotationPitch; float f1 = playerIn.rotationYaw; double d0 = playerIn.posX; double d1 = playerIn.posY + (double) playerIn.getEyeHeight(); double d2 = playerIn.posZ; Vec3d vec3d = new Vec3d(d0, d1, d2); float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI); float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI); float f4 = -MathHelper.cos(-f * 0.017453292F); float f5 = MathHelper.sin(-f * 0.017453292F); float f6 = f3 * f4; float f7 = f2 * f4; double d3 = 5.0D; if(playerIn instanceof net.minecraft.entity.player.EntityPlayerMP) { d3 = ((net.minecraft.entity.player.EntityPlayerMP) playerIn).interactionManager.getBlockReachDistance(); } Vec3d vec3d1 = vec3d.add((double) f6 * d3, (double) f5 * d3, (double) f7 * d3); return worldIn.rayTraceBlocks(vec3d, vec3d1, useLiquids, !useLiquids, false); }
public static LookDirection getPlayerRay( final EntityPlayer playerIn, final float eyeOffset ) { double reachDistance = 5.0d; final double x = playerIn.prevPosX + ( playerIn.posX - playerIn.prevPosX ); final double y = playerIn.prevPosY + ( playerIn.posY - playerIn.prevPosY ) + playerIn.getEyeHeight(); final double z = playerIn.prevPosZ + ( playerIn.posZ - playerIn.prevPosZ ); final float playerPitch = playerIn.prevRotationPitch + ( playerIn.rotationPitch - playerIn.prevRotationPitch ); final float playerYaw = playerIn.prevRotationYaw + ( playerIn.rotationYaw - playerIn.prevRotationYaw ); final float yawRayX = MathHelper.sin( -playerYaw * 0.017453292f - (float) Math.PI ); final float yawRayZ = MathHelper.cos( -playerYaw * 0.017453292f - (float) Math.PI ); final float pitchMultiplier = -MathHelper.cos( -playerPitch * 0.017453292F ); final float eyeRayY = MathHelper.sin( -playerPitch * 0.017453292F ); final float eyeRayX = yawRayX * pitchMultiplier; final float eyeRayZ = yawRayZ * pitchMultiplier; if( playerIn instanceof EntityPlayerMP ) { reachDistance = ( (EntityPlayerMP) playerIn ).interactionManager.getBlockReachDistance(); } final Vec3d from = new Vec3d( x, y, z ); final Vec3d to = from.addVector( eyeRayX * reachDistance, eyeRayY * reachDistance, eyeRayZ * reachDistance ); return new LookDirection( from, to ); }
@Override public void onBlockClicked( World worldIn, BlockPos pos, EntityPlayer playerIn ) { if( Platform.isClient() ) { final RayTraceResult rtr = Minecraft.getMinecraft().objectMouseOver; if( rtr != null && rtr.typeOfHit == Type.BLOCK && pos.equals( rtr.getBlockPos() ) ) { final Vec3d hitVec = rtr.hitVec.subtract( new Vec3d( pos ) ); if( this.cb( worldIn, pos ).clicked( playerIn, EnumHand.MAIN_HAND, hitVec ) ) { NetworkHandler.instance() .sendToServer( new PacketClick( pos, rtr.sideHit, (float) hitVec.x, (float) hitVec.y, (float) hitVec.z, EnumHand.MAIN_HAND, true ) ); } } } }
private BakedQuad createQuad( EnumFacing side, Vec3d c1, Vec3d c2, Vec3d c3, Vec3d c4, TextureAtlasSprite sprite, float uOffset, float vOffset ) { Vec3d normal = new Vec3d( side.getDirectionVec() ); // Apply the u,v shift. // This mirrors the logic from OffsetIcon from 1.7 float u1 = MathHelper.clamp( 0 - uOffset, 0, 16 ); float u2 = MathHelper.clamp( 16 - uOffset, 0, 16 ); float v1 = MathHelper.clamp( 0 - vOffset, 0, 16 ); float v2 = MathHelper.clamp( 16 - vOffset, 0, 16 ); UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder( this.vertexFormat ); builder.setTexture( sprite ); this.putVertex( builder, normal, c1.x, c1.y, c1.z, sprite, u1, v1 ); this.putVertex( builder, normal, c2.x, c2.y, c2.z, sprite, u1, v2 ); this.putVertex( builder, normal, c3.x, c3.y, c3.z, sprite, u2, v2 ); this.putVertex( builder, normal, c4.x, c4.y, c4.z, sprite, u2, v1 ); return builder.build(); }
final SelectedPart sp = ( (IPartHost) te ).selectPart( new Vec3d( hitX, hitY, hitZ ) ); if( sp.part instanceof IUpgradeableHost )
if( block instanceof BlockCableBus ) ( (BlockCableBus) block ).onBlockClickPacket( player.world, pos, player, this.hand, new Vec3d( this.hitX, this.hitY, this.hitZ ) );