Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
- //called when the block is left-clicked, but does not have hitX Y Z ...
- TileEntity tile = worldIn.getTileEntity(pos);
- if(! (tile instanceof TileEntityDustPlaced)){
- //something is wrong
- WizardryLogger.logError("The TileEntity attached to the BlockDustPlaced at "+pos+" has bad type: "+tile.getClass());
- }
- TileEntityDustPlaced tileDust = (TileEntityDustPlaced) tile;
- //Vec3 look = playerIn.rayTrace(blockReachDistance, partialTicks) //client side only
- //Vec3 look = playerIn.getLookVec();//normalized to player's coords
- //denormalize the vector
- //look = look.add(playerIn.getPositionVector());
- if(!worldIn.isRemote){
- MovingObjectPosition hitPos = RayTracer.retraceBlock(worldIn, playerIn, pos);
- //MovingObjectPosition hitPos = codechicken.lib.raytracer.RayTracer.retraceBlock(worldIn, playerIn, pos);
- Vec3 look = hitPos.hitVec;//this is null client side
- WizardryLogger.logInfo("DustPlaced block clicked. pos= "+pos+" lookX: "+look.xCoord+" lookY: "+look.yCoord+" lookZ: "+look.zCoord);
- //NW corner has hitX:0.09 hitZ:0.09
- //NE corner has hitX:0.9 hitZ 0.09
- //SE Corner has hitX 0.9 hitZ 0.9
- //SW corner has hitX:0.02 hitZ 0.9
- //make it relative to the block hit
- double posX = (look.xCoord - (double)pos.getX() )* (double)TileEntityDustPlaced.COLS;
- double posZ = (look.zCoord - (double)pos.getZ() )* (double)TileEntityDustPlaced.ROWS;
- int row = (int) posZ;
- int col = (int) posX;
- WizardryLogger.logInfo("Slot coords is "+row+" "+col);
- //make sure we are within bounds
- if(row<0)row=0;
- if(row>TileEntityDustPlaced.ROWS-1)row=TileEntityDustPlaced.ROWS-1;
- if(col<0)col=0;
- if(col>TileEntityDustPlaced.COLS-1)col=TileEntityDustPlaced.COLS-1;
- int slotID = TileEntityDustPlaced.getSlotIDfromPosition(row, col);
- ItemStack dustStack = tileDust.getStackInSlot(slotID);
- if (dustStack !=null){
- //drop the dust piece
- tileDust.setInventorySlotContents(slotID, null);
- 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);
- //drop the itemStack
- if(!playerIn.capabilities.isCreativeMode)spawnAsEntity(worldIn, pos, dustStack);
- if(tileDust.isEmpty()){//if there is no more dust, break the block
- this.breakBlock(worldIn, pos, worldIn.getBlockState(pos));
- worldIn.setBlockToAir(pos);
- }
- }
- worldIn.markBlockForUpdate(pos);
- }else{
- }
- }
Add Comment
Please, Sign In to add comment