1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Block Nuker

Discussion in 'Development' started by CreeperFace, Dec 18, 2016.

  1. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    Hi i would like to make some anticheat to prevent players breaking blocks through other bocks.

    there is a picture:
    upload_2016-12-18_22-1-19.png
    i only need to check if player can see this block (and can touch it), or if there are other blocks.
    I don't know if its possible, because i haven't found any tutorial.
     
  2. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    what do you mean about this code? Could work? :D

    PHP:
    public RayTraceResult rayTraceBlocks(Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock)
    {
        if (!
    Double.isNaN(vec31.xCoord) && !Double.isNaN(vec31.yCoord) && !Double.isNaN(vec31.zCoord))
        {
            if (!
    Double.isNaN(vec32.xCoord) && !Double.isNaN(vec32.yCoord) && !Double.isNaN(vec32.zCoord))
            {
                
    int i = MathHelper.floor_double(vec32.xCoord);
                
    int j = MathHelper.floor_double(vec32.yCoord);
                
    int k = MathHelper.floor_double(vec32.zCoord);
                
    int l = MathHelper.floor_double(vec31.xCoord);
                
    int i1 = MathHelper.floor_double(vec31.yCoord);
                
    int j1 = MathHelper.floor_double(vec31.zCoord);
                
    BlockPos blockpos = new BlockPos(l, i1, j1);
                
    IBlockState iblockstate = this.getBlockState(blockpos);
                
    Block block = iblockstate.getBlock();

                if ((!
    ignoreBlockWithoutBoundingBox || iblockstate.getCollisionBoundingBox(this, blockpos) != Block.NULL_AABB) && block.canCollideCheck(iblockstate, stopOnLiquid))
                {
                    
    RayTraceResult raytraceresult = iblockstate.collisionRayTrace(this, blockpos, vec31, vec32);

                    if (
    raytraceresult != null)
                    {
                        return 
    raytraceresult;
                    }
                }

                
    RayTraceResult raytraceresult2 = null;
                
    int k1 = 200;

                while (
    k1-- >= 0)
                {
                    if (
    Double.isNaN(vec31.xCoord) || Double.isNaN(vec31.yCoord) || Double.isNaN(vec31.zCoord))
                    {
                        return 
    null;
                    }

                    if (
    l == i && i1 == j && j1 == k)
                    {
                        return 
    returnLastUncollidableBlock ? raytraceresult2 : null;
                    }

                    
    boolean flag2 = true;
                    
    boolean flag = true;
                    
    boolean flag1 = true;
                    
    double d0 = 999.0D;
                    
    double d1 = 999.0D;
                    
    double d2 = 999.0D;

                    if (
    i > l)
                    {
                        
    d0 = (double)l + 1.0D;
                    }
                    else if (
    i < l)
                    {
                        
    d0 = (double)l + 0.0D;
                    }
                    else
                    {
                        
    flag2 = false;
                    }

                    if (
    j > i1)
                    {
                        
    d1 = (double)i1 + 1.0D;
                    }
                    else if (
    j < i1)
                    {
                        
    d1 = (double)i1 + 0.0D;
                    }
                    else
                    {
                        
    flag = false;
                    }

                    if (
    k > j1)
                    {
                        
    d2 = (double)j1 + 1.0D;
                    }
                    else if (
    k < j1)
                    {
                        
    d2 = (double)j1 + 0.0D;
                    }
                    else
                    {
                        
    flag1 = false;
                    }

                    
    double d3 = 999.0D;
                    
    double d4 = 999.0D;
                    
    double d5 = 999.0D;
                    
    double d6 = vec32.xCoord - vec31.xCoord;
                    
    double d7 = vec32.yCoord - vec31.yCoord;
                    
    double d8 = vec32.zCoord - vec31.zCoord;

                    if (
    flag2)
                    {
                        
    d3 = (d0 - vec31.xCoord) / d6;
                    }

                    if (
    flag)
                    {
                        
    d4 = (d1 - vec31.yCoord) / d7;
                    }

                    if (
    flag1)
                    {
                        
    d5 = (d2 - vec31.zCoord) / d8;
                    }

                    if (
    d3 == -0.0D)
                    {
                        
    d3 = -1.0E-4D;
                    }

                    if (
    d4 == -0.0D)
                    {
                        
    d4 = -1.0E-4D;
                    }

                    if (
    d5 == -0.0D)
                    {
                        
    d5 = -1.0E-4D;
                    }

                    
    EnumFacing enumfacing;

                    if (
    d3 < d4 && d3 < d5)
                    {
                        
    enumfacing = i > l ? EnumFacing.WEST : EnumFacing.EAST;
                        
    vec31 = new Vec3d(d0, vec31.yCoord + d7 * d3, vec31.zCoord + d8 * d3);
                    }
                    else if (
    d4 < d5)
                    {
                        
    enumfacing = j > i1 ? EnumFacing.DOWN : EnumFacing.UP;
                        
    vec31 = new Vec3d(vec31.xCoord + d6 * d4, d1, vec31.zCoord + d8 * d4);
                    }
                    else
                    {
                        
    enumfacing = k > j1 ? EnumFacing.NORTH : EnumFacing.SOUTH;
                        
    vec31 = new Vec3d(vec31.xCoord + d6 * d5, vec31.yCoord + d7 * d5, d2);
                    }

                    
    l = MathHelper.floor_double(vec31.xCoord) - (enumfacing == EnumFacing.EAST ? 1 : 0);
                    
    i1 = MathHelper.floor_double(vec31.yCoord) - (enumfacing == EnumFacing.UP ? 1 : 0);
                    
    j1 = MathHelper.floor_double(vec31.zCoord) - (enumfacing == EnumFacing.SOUTH ? 1 : 0);
                    
    blockpos = new BlockPos(l, i1, j1);
                    
    IBlockState iblockstate1 = this.getBlockState(blockpos);
                    
    Block block1 = iblockstate1.getBlock();

                    if (!
    ignoreBlockWithoutBoundingBox || iblockstate1.getMaterial() == Material.PORTAL || iblockstate1.getCollisionBoundingBox(this, blockpos) != Block.NULL_AABB)
                    {
                        if (
    block1.canCollideCheck(iblockstate1, stopOnLiquid))
                        {
                            
    RayTraceResult raytraceresult1 = iblockstate1.collisionRayTrace(this, blockpos, vec31, vec32);

                            if (
    raytraceresult1 != null)
                            {
                                return 
    raytraceresult1;
                            }
                        }
                        else
                        {
                            
    raytraceresult2 = new RayTraceResult(RayTraceResult.Type.MISS, vec31, enumfacing, blockpos);
                        }
                    }
                }

                return 
    returnLastUncollidableBlock ? raytraceresult2 : null;
            }
            else
            {
                return 
    null;
            }
        }
        else
        {
            return 
    null;
        }
    }
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Check the xyz and +1 each of em, and see if they are breaking it
     
  4. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    one block in front of player?
     
  5. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    sorta like $player->getX() + 1 or getY() + 1 idk the exact code but u can do that
     
  6. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    image is wrong :D because player can touch the block even on top side in this case :D
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Note that server and client position reference may have minor inconsistency that leads to wrong calculation.
     
  8. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    Hmmm and is the code from minecraft what i need?
     
  9. CreeperFace

    CreeperFace Witch

    Messages:
    58
    GitHub:
    creeperface01
    or is there any better way how to check this? :/
     
  10. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Worth looking into Ray Tracing
    dont ask me how doe, i am bad at math
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.