Guest User

Untitled

a guest
Jan 3rd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.60 KB | None | 0 0
  1.     @Override
  2.     public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
  3.         //called when the block is left-clicked, but does not have hitX Y Z ...
  4.             TileEntity tile = worldIn.getTileEntity(pos);
  5.             if(! (tile instanceof TileEntityDustPlaced)){
  6.                 //something is wrong
  7.                 WizardryLogger.logError("The TileEntity attached to the BlockDustPlaced at "+pos+" has bad type: "+tile.getClass());
  8.             }
  9.             TileEntityDustPlaced tileDust = (TileEntityDustPlaced) tile;
  10.             //Vec3 look = playerIn.rayTrace(blockReachDistance, partialTicks) //client side only
  11.             //Vec3 look = playerIn.getLookVec();//normalized to player's coords
  12.             //denormalize the vector
  13.             //look = look.add(playerIn.getPositionVector());
  14.         if(!worldIn.isRemote){
  15.             MovingObjectPosition hitPos = RayTracer.retraceBlock(worldIn, playerIn, pos);
  16.             //MovingObjectPosition hitPos = codechicken.lib.raytracer.RayTracer.retraceBlock(worldIn, playerIn, pos);
  17.             Vec3 look = hitPos.hitVec;//this is null client side
  18.             WizardryLogger.logInfo("DustPlaced block clicked. pos= "+pos+" lookX: "+look.xCoord+" lookY: "+look.yCoord+" lookZ: "+look.zCoord);
  19.             //NW corner has hitX:0.09 hitZ:0.09
  20.             //NE corner has hitX:0.9 hitZ 0.09
  21.             //SE Corner has hitX 0.9 hitZ 0.9
  22.             //SW corner has hitX:0.02 hitZ 0.9
  23.             //make it relative to the block hit
  24.             double posX = (look.xCoord - (double)pos.getX() )* (double)TileEntityDustPlaced.COLS;
  25.             double posZ = (look.zCoord - (double)pos.getZ() )* (double)TileEntityDustPlaced.ROWS;
  26.             int row = (int) posZ;
  27.             int col = (int) posX;
  28.  
  29.             WizardryLogger.logInfo("Slot coords is "+row+" "+col);
  30.             //make sure we are within bounds
  31.             if(row<0)row=0;
  32.             if(row>TileEntityDustPlaced.ROWS-1)row=TileEntityDustPlaced.ROWS-1;
  33.             if(col<0)col=0;
  34.             if(col>TileEntityDustPlaced.COLS-1)col=TileEntityDustPlaced.COLS-1;
  35.  
  36.             int slotID = TileEntityDustPlaced.getSlotIDfromPosition(row, col);
  37.  
  38.             ItemStack dustStack = tileDust.getStackInSlot(slotID);
  39.  
  40.             if (dustStack !=null){
  41.                 //drop the dust piece
  42.                 tileDust.setInventorySlotContents(slotID, null);
  43.                 worldIn.playSoundEffect(pos.getX() + 0.5F, pos.getY() + 0.5F, pos.getZ() + 0.5F, Block.soundTypeSand.getBreakSound(), (Block.soundTypeSand.getVolume() + 1.0F) / 2.0F, Block.soundTypeGrass.getFrequency() * 0.8F);
  44.                 //drop the itemStack
  45.                 if(!playerIn.capabilities.isCreativeMode)spawnAsEntity(worldIn, pos, dustStack);
  46.                 if(tileDust.isEmpty()){//if there is no more dust, break the block
  47.                     this.breakBlock(worldIn, pos, worldIn.getBlockState(pos));
  48.                     worldIn.setBlockToAir(pos);
  49.                 }
  50.             }
  51.             worldIn.markBlockForUpdate(pos);
  52.         }else{
  53.         }
  54.     }
Add Comment
Please, Sign In to add comment